Spaces:
Sleeping
Sleeping
Merge pull request #23 from lfoppiano/manage-conversational-memory
Browse files
document_qa/document_qa_engine.py
CHANGED
|
@@ -169,7 +169,9 @@ class DocumentQAEngine:
|
|
| 169 |
relevant_documents = retriever.get_relevant_documents(query)
|
| 170 |
if self.memory and len(self.memory.buffer_as_messages) > 0:
|
| 171 |
relevant_documents.append(
|
| 172 |
-
Document(
|
|
|
|
|
|
|
| 173 |
)
|
| 174 |
return relevant_documents
|
| 175 |
|
|
@@ -257,8 +259,9 @@ class DocumentQAEngine:
|
|
| 257 |
metadatas=metadata,
|
| 258 |
collection_name=hash)
|
| 259 |
else:
|
| 260 |
-
if 'documents' in self.embeddings_dict[hash].get() and len(self.embeddings_dict[hash].get()['documents']) == 0:
|
| 261 |
-
|
|
|
|
| 262 |
self.embeddings_dict[hash] = Chroma.from_texts(texts,
|
| 263 |
embedding=self.embedding_function,
|
| 264 |
metadatas=metadata,
|
|
|
|
| 169 |
relevant_documents = retriever.get_relevant_documents(query)
|
| 170 |
if self.memory and len(self.memory.buffer_as_messages) > 0:
|
| 171 |
relevant_documents.append(
|
| 172 |
+
Document(
|
| 173 |
+
page_content="""Following, the previous question and answers. Use these information only when in the question there are unspecified references:\n{}\n\n""".format(
|
| 174 |
+
self.memory.buffer_as_str))
|
| 175 |
)
|
| 176 |
return relevant_documents
|
| 177 |
|
|
|
|
| 259 |
metadatas=metadata,
|
| 260 |
collection_name=hash)
|
| 261 |
else:
|
| 262 |
+
# if 'documents' in self.embeddings_dict[hash].get() and len(self.embeddings_dict[hash].get()['documents']) == 0:
|
| 263 |
+
# self.embeddings_dict[hash].delete(ids=self.embeddings_dict[hash].get()['ids'])
|
| 264 |
+
self.embeddings_dict[hash].delete_collection()
|
| 265 |
self.embeddings_dict[hash] = Chroma.from_texts(texts,
|
| 266 |
embedding=self.embedding_function,
|
| 267 |
metadatas=metadata,
|