diff --git a/libs/langchain/langchain/memory/vectorstore.py b/libs/langchain/langchain/memory/vectorstore.py index b368fbab38bd3..7b3a67de716c1 100644 --- a/libs/langchain/langchain/memory/vectorstore.py +++ b/libs/langchain/langchain/memory/vectorstore.py @@ -73,4 +73,14 @@ def save_context(self, inputs: Dict[str, Any], outputs: Dict[str, str]) -> None: self.retriever.add_documents(documents) def clear(self) -> None: - """Nothing to clear.""" + """Only for faiss vectorstore """ + """Clear the chat_history in faiss vector_store""" + if self.retriever.__dict__['tags'] == ['FAISS']: + self.retriever.vectorstore.delete(self.check_history_id()) + else: + raise NotImplementedError("clear method must be implemented by faiss vector store.") + def check_history_id(self) -> List[str]: + """Check the existed history memory in the faiss retrieval VectorStore.""" + return list( + self.retriever.vectorstore.__dict__["index_to_docstore_id"].values() + )