Replies: 1 comment 2 replies
-
To store the agent's response in a local FAISS vector database and retrieve it later, even after restarting the kernel, you can follow these steps:
Here's a code example demonstrating these steps: import datetime
import tempfile
from langchain_community.vectorstores.faiss import FAISS
from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings
# Step 1: Store the response
texts = ["agent response 1", "agent response 2", "agent response 3"]
docsearch = FAISS.from_texts(texts, FakeEmbeddings())
# Save the FAISS index locally
temp_timestamp = datetime.datetime.utcnow().strftime("%Y%m%d-%H%M%S")
with tempfile.TemporaryDirectory(suffix="_" + temp_timestamp + "/") as temp_folder:
docsearch.save_local(temp_folder)
# Step 2: Retrieve the response after restarting the kernel
new_docsearch = FAISS.load_local(
temp_folder, FakeEmbeddings(), allow_dangerous_deserialization=True
)
# Now you can use `new_docsearch` to perform similarity searches
output = new_docsearch.similarity_search("agent response 1", k=1)
print(output) This code snippet demonstrates how to store and retrieve agent responses using a FAISS vector database, ensuring persistence across kernel restarts [1][2]. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
-
In this code, I am losing the context as soon as I restart the kernel. Is that possible to store thread_1 response in local vector db? and retrieve it? Please help.
Beta Was this translation helpful? Give feedback.
All reactions