You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added owner_sid to the documents table to determine the ownership of documents by users and only allow users with sid (uuid) to query their own documents. Here is the SQL snippet I have customized. I am unsure how to pass the user sid when 'embedding' and 'querying' though.
-- Enable the pgvector extension to work with embedding vectors
create extension vector;
-- Create a table to store your documentscreatetabledocuments (
id bigserialprimary key,
content text, -- corresponds to Document.pageContent
metadata jsonb, -- corresponds to Document.metadata
embedding vector(1536), -- 1536 works for OpenAI embeddings, change if needed-- customize
owner_sid uuid not null-- only users can query their documents
);
-- Create a function to search for documentscreatefunctionmatch_documents (
query_embedding vector(1536),
match_count int,
-- owner
document_owner uuid
) returns table (
id bigint,
content text,
metadata jsonb,
similarity float
)
language plpgsql
as $$
#variable_conflict use_columnbegin
return query
select
id,
content,
metadata,
1- (documents.embedding<=> query_embedding) as similarity,
-- owner
owner_sid
from documents
order bydocuments.embedding<=> query_embedding
limit match_count;
end;
$$;
-- Create an index to be used by the search functioncreateindexon documents
using ivfflat (embedding vector_cosine_ops)
with (lists =100);
The text was updated successfully, but these errors were encountered:
Hello,
This is not an issue, just a question need help:
I added
owner_sid
to thedocuments
table to determine the ownership of documents by users and only allow users withsid
(uuid) to query their own documents. Here is the SQL snippet I have customized. I am unsure how to pass the usersid
when'embedding'
and'querying'
though.The text was updated successfully, but these errors were encountered: