chroma: [Bug]: RuntimeError: Cannot return the results in a contigious 2D array. Probably ef or M is too small
What happened?
I have the following code to initialize the db client and get the collections:
def initialize_vectordb(client_path,collections_name):
vectordb_client = chromadb.PersistentClient(path=client_path)
collections = vectordb_client.get_or_create_collection(name=collections_name)
return vectordb_client,collections
and here is the code to add documents to my db:
collections.add(
documents=docs,
embeddings=embeddings,
metadatas=metadatas,
ids=ids
)
and following code to query the db:
column_len = len(collections.get(where={"source":"column"})["ids"])
file_len = len(collections.get(where={"source":"file"})["ids"])
text_embeddings = embeddings_model(text)
file_results = collections.query(
query_embeddings=text_embeddings,
n_results=file_len,
where={"source":"file"}
)
Everytime when I perform initialization of db, adding documents to db followed by query in the same session, it works perfectly fine. But when I terminate the session, then initialize the db followed by query, it will shows the error:
RuntimeError: Cannot return the results in a contigious 2D array. Probably ef or M is too small
Basically, initialize_new_db -> add_docs to new db -> query db✅ Works fine start new session -> initialize_persistent_client_db -> query db ❌ shows error
Versions
Chroma v0.4.2 Python 3.8.15
Relevant log output
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 18 (5 by maintainers)
Hi, I solved this problem with this
client.get_or_create_collection(COLLECTION_NAME,metadata={"hnsw:M": 64})you can pass M size with metadata and resize until when error is gone. good luck