langchainjs: SupabaseFilterRPCCall does not work, Error: PGRST202 Could not find the function public.match_documents(query_embedding)

Related doc: https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/supabase

Correct


const vectorStore = await SupabaseVectorStore.fromExistingIndex(new OpenAIEmbeddings(), {
    client: supabaseClient,
    // https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/supabase
    filter: { source: videoUrl },
  })

Incorrect

After migrating to use SupabaseFilterRPCCall, failed:

const funcFilterByCollection: SupabaseFilterRPCCall = (rpc) =>
    // rpc.filter('metadata->>source', 'in', `(${contentUrls.join(',')})`)
    rpc.filter('metadata->>source', 'eq', videoUrl)

  const embeddings = new OpenAIEmbeddings()
  const vectorStore = new SupabaseVectorStore(embeddings, {
    client: supabaseClient,
    tableName: 'documents',
    filter: funcFilterByCollection
  })

Error message

- error node_modules/langchain/dist/vectorstores/supabase.js (79:18) @ SupabaseVectorStore.similaritySearchVectorWithScore
- error Error searching for documents: PGRST202 Could not find the function public.match_documents(query_embedding) in the schema cache Searched for the function public.match_documents with parameter query_embedding or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache.

Error searching for documents: PGRST202 Could not find the function public.match_documents(query_embedding) in the schema cache Searched for the function public.match_documents with parameter query_embedding or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 18 (3 by maintainers)

Most upvoted comments

Thank you, I had a similar problem and fixed it by dropping and recreating the function per the latest docs

-- Drop old function
drop function if exists match_documents (vector(1536), int);

-- Create a function to search for documents
create function match_documents (
  query_embedding vector(1536),
  match_count int DEFAULT null,
  filter jsonb DEFAULT '{}'
) returns table (
  id bigint,
  content text,
  metadata jsonb,
  similarity float
)
language plpgsql
as $$
#variable_conflict use_column
begin
  return query
  select
    id,
    content,
    metadata,
    1 - (documents.embedding <=> query_embedding) as similarity
  from documents
  where metadata @> filter
  order by documents.embedding <=> query_embedding
  limit match_count;
end;
$$;

@JimmyLv Have you solved this problem? if not, can DM me. BTW, love your BilbiGPT.

@hwchase17 @supabase any idea? 😁

It still doesn’t work, I’m pretty sure I definitely have this match_documents function and I’m able to get it to work through the REST API.

Supabase-Google Chrome

Postman-Postman

Answer generated by a 🤖

Answer

The error message “PGRST202 Could not find the function public.match_documents(query_embedding)” indicates that the function match_documents is not found in your database schema. This function is required for the SupabaseVectorStore to perform similarity searches.

The match_documents function is expected to be present in your database as it is used for similarity search in the SupabaseVectorStore class. If the function does not exist, you need to create it. The function should take a query embedding and return the matched documents. The exact implementation of the function depends on your specific use case and database structure.

In your incorrect code, the queryName parameter is not specified when creating the SupabaseVectorStore. This could be the reason why the match_documents function is not found. To fix this issue, you should specify the queryName parameter when creating the SupabaseVectorStore:

const embeddings = new OpenAIEmbeddings()
const vectorStore = new SupabaseVectorStore(embeddings, {
  client: supabaseClient,
  tableName: 'documents',
  queryName: 'match_documents', // Add this line
  filter: funcFilterByCollection
})

Please ensure that the match_documents function exists in your Supabase database and is accessible by the client. If the function is present but still not found, make sure that it’s in the correct schema and that the schema is included in the search path. Also, ensure that the function accepts the correct parameters. The error message suggests that the function should either accept a parameter named query_embedding or a single unnamed json/jsonb parameter.

If the error persists, you should check your Supabase database to ensure that the match_documents function exists and is correctly defined. If you have a different function name in your database, you should provide it while creating an instance of SupabaseHybridSearch

Sources


This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

I’ve tried adding queryName but it still doesn’t work

const embeddings = new OpenAIEmbeddings()
const vectorStore = new SupabaseVectorStore(embeddings, {
  client: supabaseClient,
  tableName: 'documents',
  queryName: 'match_documents', // Add this line
  filter: funcFilterByCollection
})