mem0 icon indicating copy to clipboard operation
mem0 copied to clipboard

Fix: Solve IndexError when no relevant documents are found in the vector db.

Open limboinf opened this issue 2 years ago • 0 comments

This PR will solve the following problem. When no similar document is found in the vector database or the vector database is empty,result_formatted[0][0].page_content will be triggered and IndexError will be triggered.

eg:


result = self.collection.query(
            query_texts=[input_query,],
            n_results=1,
        )


# the result will be:
# {'ids': [[]], 'embeddings': None, 'documents': [[]], 'metadatas': [[]], 'distances': [[]]}

# and then, result_formatted = self._format_result(result) will return empty list.
# []

limboinf avatar Jun 25 '23 08:06 limboinf