langchain@embedding_search
embedding_search
LangChain is a framework for developing applications powered by language models with a plugable architecture.
langchain@embedding_search
uses a Supabase Postgres database as its vector store.
Installation
select dbdev.install('langchain@embedding_search');
create extension if not exists vector;
create extension "langchain@embedding_search"
schema public
version '1.1.0';
Note:
vector
is a dependency of langchain@embedding_search
.
Dependency resolution is currently under development.
In the near future it will not be necessary to manually create dependencies.
Standard Usage
The below example shows how to perform a basic similarity search with Supabase:
Once created, you can access the vector store for search using langchain as shown below:
import { SupabaseVectorStore } from "langchain/vectorstores/supabase";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { createClient } from "@supabase/supabase-js";
const privateKey = process.env.SUPABASE_PRIVATE_KEY;
if (!privateKey) throw new Error(`Expected env var SUPABASE_PRIVATE_KEY`);
const url = process.env.SUPABASE_URL;
if (!url) throw new Error(`Expected env var SUPABASE_URL`);
export const run = async () => {
const client = createClient(url, privateKey);
const vectorStore = await SupabaseVectorStore.fromTexts(
["Hello world", "Bye bye", "What's this?"],
[{ id: 2 }, { id: 1 }, { id: 3 }],
new OpenAIEmbeddings(),
{
client,
tableName: "documents",
queryName: "match_documents",
}
);
const resultOne = await vectorStore.similaritySearch("Hello world", 1);
console.log(resultOne);
};
Metadata Filtering
Given the above match_documents
Postgres function, you can also pass a filter parameter to only documents with a specific metadata field value.
import { SupabaseVectorStore } from "langchain/vectorstores/supabase";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { createClient } from "@supabase/supabase-js";
// First, follow set-up instructions at
// https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/supabase
const privateKey = process.env.SUPABASE_PRIVATE_KEY;
if (!privateKey) throw new Error(`Expected env var SUPABASE_PRIVATE_KEY`);
const url = process.env.SUPABASE_URL;
if (!url) throw new Error(`Expected env var SUPABASE_URL`);
export const run = async () => {
const client = createClient(url, privateKey);
const vectorStore = await SupabaseVectorStore.fromTexts(
["Hello world", "Hello world", "Hello world"],
[{ user_id: 2 }, { user_id: 1 }, { user_id: 3 }],
new OpenAIEmbeddings(),
{
client,
tableName: "documents",
queryName: "match_documents",
}
);
const result = await vectorStore.similaritySearch("Hello world", 1, {
user_id: 3,
});
console.log(result);
};
For more details, checkout the LangChain Supabase integration docs: https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/supabase
Install
- Install the
dbdev
package manager - Install the package:
select dbdev.install('langchain@embedding_search');
create extension "langchain@embedding_search"
version '1.1.1';
Downloads
- 83 all time downloads
- 0 downloads in the last 30 days
- 1 download in the last 90 day
- 2 downloads in the last 180 days