LangChain
LangChain is a popular framework for working with AI, Vectors, and embeddings. LangChain supports using Supabase as a vector store, using the pgvector
extension.
Initializing your database
Prepare you database with the relevant tables:
- Go to the SQL Editor page in the Dashboard.
- Click LangChain in the Quick start section.
- Click Run.
Usage
You can now search your documents using any Node.js application. This is intended to be run on a secure server route.
Simple metadata filtering
Given the above match_documents
Postgres function, you can also pass a filter parameter to only return documents with a specific metadata field value. This filter parameter is a JSON object, and the match_documents
function will use the Postgres JSONB Containment operator @>
to filter documents by the metadata field values you specify. See details on the Postgres JSONB Containment operator for more information.
Advanced metadata filtering
You can also use query builder-style filtering (similar to how the Supabase JavaScript library works) instead of passing an object. Note that since the filter properties will be in the metadata column, you need to use arrow operators (->
for integer or ->>
for text) as defined in Postgrest API documentation and specify the data type of the property (e.g. the column should look something like metadata->some_int_value::int
).
Hybrid search
LangChain supports the concept of a hybrid search, which combines Similarity Search with Full Text Search. Read the official docs to get started: Supabase Hybrid Search.
You can install the LangChain Hybrid Search function though our database.dev package manager.
Resources
- Official LangChain site.
- Official LangChain docs.
- Supabase Hybrid Search.