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

[Bug]ChromaDB Knowledge Search Error - Error searching for documents: list indices must be integers or slices, not str #2059

Open
YuviCrypter opened this issue Feb 10, 2025 · 0 comments · May be fixed by #2060
Labels
bug Something isn't working

Comments

@YuviCrypter
Copy link

Description

Using ChromaDB as Vector Database of Knowledge Base is always giving response - No Documents Found.
After calling the search function on Knowledge Base, It logs "Error searching for documents: list indices must be integers or slices, not str"

Steps to Reproduce

Create a Knowledge Base like this:

from agno.agent import AgentKnowledge
from agno.embedder.sentence_transformer import SentenceTransformerEmbedder
from agno.vectordb.chroma import ChromaDb

knowledge_base = AgentKnowledge(
    vector_db=ChromaDb(
        collection="collection_name",
        persistent_client=True,
        path="path/to/db",
        embedder=SentenceTransformerEmbedder(
            id="all-mpnet-base-v2" # I was using this embedding model.
        )
    ),
)

docs = knowledge_base.search(query="Some Query",num_documents=5)
for doc in docs:
    print(doc,"\n\n")

Expected Behavior

It should have Listed down 5 relevant documents from the Persistent ChromaDB.

Actual Behavior

It logged the Error saying "Error searching for documents: list indices must be integers or slices, not str" and returned empty list of Documents.

Screenshots or Logs (if applicable)

Image

Environment

  • OS: Ubuntu Linux
  • Agno Version: 1.0.4
  • Additional Environment Details: Python 3.12.8

Possible Solutions (optional)

At this code in the file agno/vectordb/chroma Line no. 205 - 214

ids = result.get("ids", [[]])[
metadata = result.get("metadatas", [[]])[0]  # type: 
documents = result.get("documents", [[]])[0]  # type: 
embeddings = result.get("
distances = result.get("distances", [[]])[0]  # type: 
uris = result.get("
data = result.get("
metadata["distances"] = distances  # type: 
metadata["uris"] = uris  # type: 
metadata["data"] = data  # type: ignore

The metadata will receive the value [[]] (list of list), But indices like "distances", "uris", "data" is directly accessed from metadata which will have value as (list of dict).
This will throw the error saying list indices must be int, not str.

@YuviCrypter YuviCrypter added the bug Something isn't working label Feb 10, 2025
YuviCrypter pushed a commit to YuviCrypter/agno-chromadb-bugfix that referenced this issue Feb 10, 2025
@YuviCrypter YuviCrypter linked a pull request Feb 10, 2025 that will close this issue
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant