|
|
@ -109,30 +109,19 @@ class Chroma(VectorStore):
|
|
|
|
) -> List[Document]:
|
|
|
|
) -> List[Document]:
|
|
|
|
"""Query the chroma collection."""
|
|
|
|
"""Query the chroma collection."""
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
import chromadb
|
|
|
|
import chromadb # noqa: F401
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
|
raise ValueError(
|
|
|
|
raise ValueError(
|
|
|
|
"Could not import chromadb python package. "
|
|
|
|
"Could not import chromadb python package. "
|
|
|
|
"Please install it with `pip install chromadb`."
|
|
|
|
"Please install it with `pip install chromadb`."
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(n_results, 0, -1):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
return self._collection.query(
|
|
|
|
return self._collection.query(
|
|
|
|
query_texts=query_texts,
|
|
|
|
query_texts=query_texts,
|
|
|
|
query_embeddings=query_embeddings,
|
|
|
|
query_embeddings=query_embeddings,
|
|
|
|
n_results=i,
|
|
|
|
n_results=n_results,
|
|
|
|
where=where,
|
|
|
|
where=where,
|
|
|
|
**kwargs,
|
|
|
|
**kwargs,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
except chromadb.errors.NotEnoughElementsException:
|
|
|
|
|
|
|
|
logger.error(
|
|
|
|
|
|
|
|
f"Chroma collection {self._collection.name} "
|
|
|
|
|
|
|
|
f"contains fewer than {i} elements."
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
raise chromadb.errors.NotEnoughElementsException(
|
|
|
|
|
|
|
|
f"No documents found for Chroma collection {self._collection.name}"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_texts(
|
|
|
|
def add_texts(
|
|
|
|
self,
|
|
|
|
self,
|
|
|
|