Skip to content

Commit a51aad7

Browse files
Merge pull request #609 from domci/364-metadata
feature(dspy): return metadata along long_text for ChromaDB retrieval
2 parents 1be2cfb + e72ef1b commit a51aad7

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

docs/api/retrieval_model_clients/ChromadbRM.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Search the chromadb collection for the top `k` passages matching the given query
3434
- `k` (_Optional[int]_, _optional_): The number of results to retrieve. If not specified, defaults to the value set during initialization.
3535

3636
**Returns:**
37-
- `dspy.Prediction`: Contains the retrieved passages, each represented as a `dotdict` with a `long_text` attribute.
37+
- `dspy.Prediction`: Contains the retrieved passages, each represented as a `dotdict` with schema `[{"id": str, "score": float, "long_text": str, "metadatas": dict }]`
3838

3939
### Quickstart with OpenAI Embeddings
4040

dspy/retrieve/chromadb_rm.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ def forward(
145145
query_embeddings=embeddings, n_results=k,
146146
)
147147

148-
passages = [dotdict({"long_text": x}) for x in results["documents"][0]]
149-
150-
return passages
148+
zipped_results = zip(
149+
results["ids"][0],
150+
results["distances"][0],
151+
results["documents"][0],
152+
results["metadatas"][0])
153+
results = [dotdict({"id": id, "score": dist, "long_text": doc, "metadatas": meta }) for id, dist, doc, meta in zipped_results]
154+
return results

0 commit comments

Comments
 (0)