-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Added filtering ability to supabase #905
feat: Added filtering ability to supabase #905
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@mishkinf @nfcampos Here's an alternate implementation, let me know what you think? In addVectors, we take in additional fields to write to in the table. So, we get to take advantage of Supabase db schema constraints. If they want to have different querying methods completely, they can have different matcher functions with different names, each with the fields being passed in as args. This way they get the benefits of the structured schemas of supabase, and get the flexibility to implement lookup in an efficient manner per match function. |
@ShantanuNair no strong opinions on my end, I merely need the functionality. One thing to note is that you could start with this implementation which essentially creates a RPC friendly way to pass filters to a supabase function, and then later on build in support to create new supabase database columns (with whatever schema constraints and functionality). The arguments of filters to the pgsql function is agnostic of the underlying data you are filtering the documents by. So in this case I am filtering data that is in metadata, but you could take this approach and use the same interface to filter the documents based on whatever db fields you have. |
@mishkinf Makes sense, soon I will create a PR with the functionality I suggested as well, you can take a look if you have the time |
I think that would be great! @ShantanuNair |
Looking forward to this! The filter param could also be generalized to accept any metadata field with CREATE FUNCTION match_documents_with_filters (
query_embedding vector(1536),
match_count int,
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;
$$; with usage: ...
const chain = ConversationalRetrievalQAChain.fromLLM(
chat,
vectorStore.asRetriever(null, {
user_id: "2",
repo: "langchain" // or any metadata field
}),
{ returnSourceDocuments: true }
);
... etc. Hope this helps! |
Honestly this is so fricken cool! I hope this happens! |
Looking forward this filtering feature in Supabase! @mishkinf PR, Looks good to me! |
Let's do this! Thanks for the PR @mishkinf |
yes! need this feature! |
…supabase-vectorstore-filtering
Added filtering ability to supabase. With the following function defined in your supabase postgres db:
You should be able to filter the documents based on fields in your document metadata:
my twitter handle: https://twitter.com/mishkinf