Retrieval Augmented Generation - Quick Start Guide
This quick start guide provides an overview of using the HyperBee Python package to manage and interact with document collections using a folder containing PDF files.
Setting Up the Client
Initialize the client with your API key, stored in an environment variable named HYPERBEE_API_KEY
.
import os
from hyperbee import HyperBee
api_key = os.environ["HYPERBEE_API_KEY"]
client = HyperBee(api_key=api_key)
Creating a Namespace and Uploading Documents
Create a namespace by uploading all PDF files from the pdf_folder
.
import os
pdf_folder = "pdf_folder"
pdf_files = [os.path.join(pdf_folder, f) for f in os.listdir(pdf_folder) if f.endswith('.pdf')]
namespace, status = client.chat.completions.create_namespace(
pdf_files, sleepseconds=10, timeoutseconds=60, verbose=True
)
print(f"Namespace created: {namespace}, Status: {status}")
Asking Questions
Interact with the uploaded documents by asking questions.
questions = ["What is the definition of the optical flow?", "What are the reasons for AI being this hard to achieve?"]
for question in questions:
response = client.chat.completions.create(
messages=[{"role": "user", "content": question}],
model="hyperchat",
namespace=namespace,
stream=False,
)
print(f"Question: {question}")
print("Answer:", response.choices[0].message.content)
Listing Documents
Retrieve a list of all documents in the namespace.
documents = client.chat.completions.get_remote_doclist(namespace)
print(f"Documents in namespace {namespace}: {documents}")
Deleting a Namespace
Delete the entire namespace along with all its documents.
client.chat.completions.delete_namespace(namespace)
print(f"Namespace {namespace} deleted.")
This quick start guide helps you set up a client, create a namespace, upload documents, ask questions, list documents, and delete namespaces using the HyperBee Python package.