Chatbot RAG Weaviate
vector-searchvector-databaseretrieval-augmented-generationllm-frameworksfunction-callingweaviate-recipesintegrationssemantic-kernelPythongenerative-aillm-agent-frameworks
Export
Introduction - A Chatbot that uses RAG with Weaviate
Implements a simple workflow of constant retrieve then generate chains. Using semantic kernel to help with prompt engineering and orchestrating calls to LLMs and Weaviate as knowledgebase from which to retreive semantically relevant context.
This chatbot not only answers using relevant retreived content but also cites sources and relevance.
Setup
[ ]
OS-specific notes:
- if you run into SSL errors when connecting to OpenAI on macOS, see this issue for a potential solution
- on Windows, you may need to run Docker Desktop as administrator
[1]
[2]
[3]
Then, we register the memory store to the kernel:
[4]
{'recall': <semantic_kernel.orchestration.sk_function.SKFunction at 0x10d5946d0>,
, 'save': <semantic_kernel.orchestration.sk_function.SKFunction at 0x12b032d50>} Adding Documents to Weaviate
Let's create some initial memories "About Me". We can add memories to our weaviate memory store by using save_information_async
[5]
[6]
[7]
Sucessfully populated memories!
[8]
Retreived document: When I turned 5 my parents gifted me goldfish for my birthday
You can retrieve k closest neighbours to a query as seen below:
[9]
I love datascience - Relevance: 0.894 my favourite food is popcorn - Relevance: 0.889 I like to take long walks. - Relevance: 0.879
We'll create a setup a prompt that will allow the LLM to use relevant context retreived from Weaviate to answer questions.
[10]
[11]
[16]
Setting up a RAG chat (with memory!) Begin chatting (type 'exit' to exit): User:> What pets did I have when I was younger? ChatBot:> It appears that you were gifted goldfish for your 5th birthday. Do you remember if you had any other pets? Source: When I turned 5 my parents gifted me goldfish for my birthday. I like to take long walks.. my favourite food is popcorn. I have a black nissan sentra. I love datascience. User:> What are some places I would enjoy traveling to in my car? ChatBot:> There are plenty of great places you can enjoy traveling to in your car. Some ideas include road trips to national parks, scenic drives along the coast, or even taking a drive to explore a nearby city. Depending on your budget, you could also look for unique attractions like drive-in movie theaters, specialty shops, and restaurants. If you're interested in data science, consider taking a road trip to explore the tech scene in Silicon Valley or explore the birthplace of data science in New York. You can also stop for some popcorn along the way as a treat for yourself. Source: I like to take long walks.. I have a black nissan sentra. my favourite food is popcorn. I love datascience. When I turned 5 my parents gifted me goldfish for my birthday. User:> exit Exiting chat...
[17]
User:> What pets did I have when I was younger? ChatBot:> It appears that you were gifted goldfish for your 5th birthday. Do you remember if you had any other pets? User:> What are some places I would enjoy traveling to in my car? ChatBot:> There are plenty of great places you can enjoy traveling to in your car. Some ideas include road trips to national parks, scenic drives along the coast, or even taking a drive to explore a nearby city. Depending on your budget, you could also look for unique attractions like drive-in movie theaters, specialty shops, and restaurants. If you're interested in data science, consider taking a road trip to explore the tech scene in Silicon Valley or explore the birthplace of data science in New York. You can also stop for some popcorn along the way as a treat for yourself.