from langchain.memory import VectorStoreRetrieverMemory
# To show that vector lookups still return semantically relevant information.
retriever = vectorstore.as_retriever(search_kwargs={"k": 1})
memory = VectorStoreRetrieverMemory(retriever=retriever)
# Save random conversations.
memory.save_context(
inputs={
"human": "Hello, thank you for coming to the interview today. Please introduce yourself."
},
outputs={
"ai": "Hello. I am a new developer majoring in computer science. In college, I mainly used Java and Python, and recently I participated in a web development project and gained experience developing services for real users."
},
)
memory.save_context(
inputs={"human": "What role did you play in the project?"},
outputs={
"ai": "My role was as a backend developer. I was in charge of processing user data and developing server logic, and I was in charge of implementing RESTful APIs to communicate with the frontend. I also participated in database design."
},
)
memory.save_context(
inputs={
"human": "If you have ever encountered difficulties on a team project, how did you resolve them?"
},
outputs={
"ai": "There were some difficulties due to communication issues at the beginning of the project. To solve this, our team had regular meetings and shared each other's progress. Also, when problems occurred, we actively shared opinions and tried to find reasonable solutions."
},
)
memory.save_context(
inputs={"human": "What do you think are your strengths as a developer?"},
outputs={
"ai": "My strengths are my ability to learn quickly and problem-solve. I can quickly learn new technologies or tools, and I can come up with creative solutions when faced with complex problems. I also value teamwork and consider it important to collaborate with my colleagues."
},
)
# Extract the single most relevant conversation by asking questions in memory.
print(memory.load_memory_variables({"prompt": "면접자 전공은 무엇인가요?"})["history"])
human: Hello, thank you for attending the interview today. Please introduce yourself.
ai: Hello. I am a new developer majoring in computer science. The university mainly used Java and Python, and recently I participated in a web development project and had the experience of developing services for real users.
print(
memory.load_memory_variables(
{"human": "What role does the interviewer play in the project?"}
)["history"]
)
human: What role did you play in the project?
ai: My role was backend developer. He was responsible for processing user data and developing server logic, and implemented the RESTful API to communicate with the front end. He also participated in database design.