1.1.0Created a month agoBy langchain


Langchain supports hybrid search with a Supabase Postgres database. The hybrid search combines the postgres pgvector extension (similarity search) and Full-Text Search (keyword search) to retrieve documents. You can add documents via SupabaseVectorStore addDocuments function. SupabaseHybridKeyWordSearch accepts embedding, supabase client, number of results for similarity search, and number of results for keyword search as parameters. The getRelevantDocuments function produces a list of documents that has duplicates removed and is sorted by relevance score.


select dbdev.install('langchain-hybrid_search');
create extension if not exists vector;
create extension "langchain-hybrid_search"
    schema public
    version '1.1.0';


vector is a dependency of langchain-hybrid_search. Dependency resolution is currently under development. In the near future it will not be necessary to manually create dependencies.

Once created, you can access the vector store for search using langchain as shown below:

import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { createClient } from "@supabase/supabase-js";
import { SupabaseHybridSearch } from "langchain/retrievers/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 embeddings = new OpenAIEmbeddings();

  const retriever = new SupabaseHybridSearch(embeddings, {
    //  Below are the defaults, expecting that you set up your supabase table and functions according to the guide above. Please change if necessary.
    similarityK: 2,
    keywordK: 2,
    tableName: "documents",
    similarityQueryName: "match_documents",
    keywordQueryName: "kw_match_documents",

  const results = await retriever.getRelevantDocuments("hello bye");


For more details, checkout the LangChain Supabase Hybrid Search docs:


  1. Install the dbdev package manager
  2. Install the package:
select dbdev.install('langchain-hybrid_search');
create extension "langchain-hybrid_search"
    version '1.1.0';


  • 8 all time downloads
  • 3 downloads in the last 30 days
  • 8 downloads in the last 90 days
  • 8 downloads in the last 180 days