From 48663a2327b082b17526a8b7c0bd13714b397e98 Mon Sep 17 00:00:00 2001 From: domci Date: Fri, 8 Mar 2024 13:35:38 +0100 Subject: [PATCH 1/2] feature(dspy): added Metadata for ChromaDB retrieval --- dspy/retrieve/chromadb_rm.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dspy/retrieve/chromadb_rm.py b/dspy/retrieve/chromadb_rm.py index 07ef407d1d..e8a892ea19 100644 --- a/dspy/retrieve/chromadb_rm.py +++ b/dspy/retrieve/chromadb_rm.py @@ -145,6 +145,10 @@ def forward( query_embeddings=embeddings, n_results=k, ) - passages = [dotdict({"long_text": x}) for x in results["documents"][0]] - - return passages + zipped_results = zip( + results["ids"][0], + results["distances"][0], + results["documents"][0], + results["metadatas"][0]) + results = [dotdict({"id": id, "score": dist, "long_text": doc, "metadatas": meta }) for id, dist, doc, meta in zipped_results] + return results From e72ef1bc2e56058b348621602307dc3149d72424 Mon Sep 17 00:00:00 2001 From: dominik Date: Sat, 9 Mar 2024 13:15:37 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9D=20(ChromadbRM.md):=20Update=20?= =?UTF-8?q?the=20return=20type=20description=20in=20the=20documentation=20?= =?UTF-8?q?The=20return=20type=20description=20for=20the=20search=20functi?= =?UTF-8?q?on=20in=20the=20ChromadbRM=20documentation=20was=20updated=20to?= =?UTF-8?q?=20provide=20more=20detailed=20information=20about=20the=20stru?= =?UTF-8?q?cture=20of=20the=20returned=20object.=20This=20change=20will=20?= =?UTF-8?q?help=20developers=20understand=20the=20structure=20of=20the=20r?= =?UTF-8?q?eturned=20object=20and=20how=20to=20use=20it=20in=20their=20cod?= =?UTF-8?q?e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/retrieval_model_clients/ChromadbRM.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/retrieval_model_clients/ChromadbRM.md b/docs/api/retrieval_model_clients/ChromadbRM.md index 42f6f42e7f..bbd1aaafd8 100644 --- a/docs/api/retrieval_model_clients/ChromadbRM.md +++ b/docs/api/retrieval_model_clients/ChromadbRM.md @@ -34,7 +34,7 @@ Search the chromadb collection for the top `k` passages matching the given query - `k` (_Optional[int]_, _optional_): The number of results to retrieve. If not specified, defaults to the value set during initialization. **Returns:** -- `dspy.Prediction`: Contains the retrieved passages, each represented as a `dotdict` with a `long_text` attribute. +- `dspy.Prediction`: Contains the retrieved passages, each represented as a `dotdict` with schema `[{"id": str, "score": float, "long_text": str, "metadatas": dict }]` ### Quickstart with OpenAI Embeddings