Skip to content

Commit

Permalink
update to the latest Document format (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
masci authored Dec 20, 2023
1 parent 65beef5 commit c17ddda
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
8 changes: 4 additions & 4 deletions integrations/chroma/example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path

from haystack import Pipeline
from haystack.components.file_converters import TextFileToDocument
from haystack.components.converters import TextFileToDocument
from haystack.components.writers import DocumentWriter

from chroma_haystack import ChromaDocumentStore
Expand All @@ -19,11 +19,11 @@
indexing.add_component("converter", TextFileToDocument())
indexing.add_component("writer", DocumentWriter(document_store))
indexing.connect("converter", "writer")
indexing.run({"converter": {"paths": file_paths}})
indexing.run({"converter": {"sources": file_paths}})

querying = Pipeline()
querying.add_component("retriever", ChromaQueryRetriever(document_store))
results = querying.run({"retriever": {"queries": ["Variable declarations"], "top_k": 3}})

for d in results["retriever"][0]:
print(d.metadata, d.score)
for d in results["retriever"]["documents"][0]:
print(d.meta, d.score)
7 changes: 1 addition & 6 deletions integrations/chroma/src/chroma_haystack/document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,6 @@ def _normalize_filters(self, filters: Dict[str, Any]) -> Tuple[List[str], Dict[s
# if the list contains multiple items, we need an $or chain
for v in value:
where["$or"].append({field: v})
elif field == "mime_type":
# Schedule for removal the original key, we're going to change it
keys_to_remove.append(field)
where["_mime_type"] = value

for k in keys_to_remove:
del filters[k]
Expand Down Expand Up @@ -310,8 +306,7 @@ def _query_result_to_documents(self, result: QueryResult) -> List[List[Document]

# prepare metadata
if metadatas := result.get("metadatas"):
document_dict["metadata"] = dict(metadatas[i][j])
document_dict["mime_type"] = document_dict["metadata"].pop("_mime_type")
document_dict["meta"] = dict(metadatas[i][j])

if embeddings := result.get("embeddings"):
document_dict["embedding"] = np.array(embeddings[i][j])
Expand Down

0 comments on commit c17ddda

Please sign in to comment.