Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow search in ChromaDocumentStore without metadata #863

Merged
merged 10 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,12 @@ def _query_result_to_documents(result: QueryResult) -> List[List[Document]]:
}

# prepare metadata
if metadatas := result.get("metadatas"):
document_dict["meta"] = dict(metadatas[i][j])
metadatas = result.get("metadatas")
try:
if metadatas and metadatas[i][j] is not None:
document_dict["meta"] = metadatas[i][j]
except IndexError:
pass

if embeddings := result.get("embeddings"):
document_dict["embedding"] = np.array(embeddings[i][j])
Expand Down
15 changes: 15 additions & 0 deletions integrations/chroma/tests/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ def test_delete_not_empty_nonexisting(self, document_store: ChromaDocumentStore)

assert document_store.filter_documents(filters={"id": doc.id}) == [doc]

def test_search(self):
document_store = ChromaDocumentStore()
documents = [
Document(content="First document", meta={"author": "Author1"}),
Document(content="Second document"), # No metadata
Document(content="Third document", meta={"author": "Author2"}),
Document(content="Fourth document"), # No metadata
]
document_store.write_documents(documents)
result = document_store.search(["Third"], top_k=1)

# Assertions to verify correctness
assert len(result) == 1
assert result[0][0].content == "Third document"

@pytest.mark.integration
def test_to_json(self, request):
ds = ChromaDocumentStore(
Expand Down
Loading