Retrieval and RAG
The canonical example of using LLMs for Retrieval Augmented Generation (RAG) is chatting with your documents. Let's use the Shakespeare writings from our Styled Generation example (opens in a new tab) as the knowledge base and ask questions about the contents.
For instance, let's take the "Allswell" comedy sketch and ask a question about the dialogues within, e.g., "what is the king ill of?", referring to this section:
BERTRAM
What is it, my good lord, the king languishes of?
LAFEU
A fistula, my lord.
BERTRAM
I heard not of it before.
The following is an example code for this using our Python Client.
Installation:
Just our client:
pip install hyperbee
RAG Example:
import os
from hyperbee import HyperBee
client = HyperBee(api_key=os.environ["HYPERBEE_API_KEY"])
def hyperchat_qa(question, namespace):
messages = [{"role": "user", "content": question}]
answer = client.chat.completions.create(model="hyperchat", optimization="premium", messages=messages, stream=False, namespace=namespace)
return answer.choices[0].message.content
response = hyperchat_qa(question="what is the king ill of?", namespace = "defd3ac0-f0b3-4b99-8024-69bf519f7686")
print(response)
Hint: the Shakespeare namespace used in this example is public, you can use the Collection ID as is in your examples
Output:
The king is suffering from a fistula, as mentioned in the context of a play.
A fistula is a medical condition that involves an abnormal connection between two body parts, such as organs or blood vessels.