PgVector >> Return all the document when we query with ID within JSON document #6109
Replies: 2 comments 3 replies
-
Hey there, @anjay-gupta! 👋 I'm here to help you with any bugs, questions, or contributions. Let's tackle this challenge together! To address the issue of retrieving specific documents based on a product ID within a JSON object while using embeddings for similarity search, you can enhance your query by focusing on the JSON metadata. Here's a step-by-step approach:
By following these steps, you should be able to retrieve documents that match the specific product ID while still leveraging the power of embeddings for similarity search. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
In the given example , below are the vector table structure and where document -> represent the josn text and having all the property including id , name , multiple address[] etc and also storing in cmetadata -> jasonb CREATE TABLE public.langchain_pg_embedding ( User ask - Please share the product details for product - P0001 Below are the PG vector component query if self.search_query and isinstance(self.search_query, str) and self.search_query.strip():
Ask is - if we provide the text including the exact ID which is present at text document and json b as metadata , still it is not able to find , Please help where it needs to improve or the best approach would be. Please share the complete example if you have. I can not add the filter i guess because user may ask question about find based on product location - like give me the product which as the NY city etc , so search should be very closer to city - just an example Looking forward to some good suggestion and pin pointed answers |
Beta Was this translation helpful? Give feedback.
-
I’m exploring ways to enhance the search functionality in a RAG (Retrieval-Augmented Generation) application, specifically to improve its ability to answer product-related questions.
We are working with a large JSON object that contains various properties, including nested objects and multiple IDs such as product ID, product status, shipping address, etc. However, when searching with a specific ID, the search returns all documents except the product ID I requested.
Could you advise on how to proceed in a scenario where we have JSON objects as metadata, and we are using embeddings for the entire JSON object while performing a similarity search?
`// DDL for embedding and vector store //
CREATE TABLE public.langchain_pg_embedding (
collection_id uuid NULL,
embedding public.vector NULL,
"document" varchar NULL,
cmetadata jsonb NULL,
custom_id varchar NULL,
"uuid" uuid NOT NULL,
CONSTRAINT langchain_pg_embedding_pkey PRIMARY KEY (uuid)
);
CREATE INDEX langchain_pg_embedding_hnsw_idx ON public.langchain_pg_embedding USING hnsw (embedding vector_l2_ops) WITH (ef_construction='200', m='16');
-- Permissions
ALTER TABLE public.langchain_pg_embedding OWNER TO postgres;
GRANT ALL ON TABLE public.langchain_pg_embedding TO postgres;
`
// Query generated the in chat when we specify the Product ID
SELECT langchain_pg_embedding.collection_id AS langchain_pg_embedding_collection_id, langchain_pg_embedding.embedding AS langchain_pg_embedding_embedding,
langchain_pg_embedding.document AS langchain_pg_embedding_document,
langchain_pg_embedding.cmetadata AS langchain_pg_embedding_cmetadata,
langchain_pg_embedding.custom_id AS langchain_pg_embedding_custom_id,
langchain_pg_embedding.uuid AS langchain_pg_embedding_uuid,
langchain_pg_embedding.embedding <=> '[-0.02035035379230976,-0.008137090131640434,-0.14020822942256927,-0.03820028156042099,0.06551223248243332, ...]' AS distance
FROM langchain_pg_embedding JOIN langchain_pg_collection ON langchain_pg_embedding.collection_id = langchain_pg_collection.uuid
WHERE langchain_pg_embedding.collection_id = '1d3628b0-6de2-4a9e-b64f-1000101001'::uuid::UUID
ORDER BY distance ASC
LIMIT 10
``
Beta Was this translation helpful? Give feedback.
All reactions