Integrations
In this section, we’ll guide you through integrating ColiVara with LLM frameworks. This integration will allow you to seamlessly connect to other moving parts in your RAG project.
Currently, we are supporting integrating with
Overview
1. Install Dependencies
2. Set up ColiVara RAG client and Process your documents
1
2
(Optional) Download your documents
You can skip this step if your documents are already downloaded into a folder. Here we are downloading documents using their URLs, and save them in the docs/
folder
# List of filenames and their URLS
files = [
{
"url": "https://github.com/tjmlabs/colivara-demo/raw/main/docs/Work-From-Home%20Guidance.pdf",
"filename": "docs/Work-From-Home-Guidance.pdf",
},
{
"url": "https://github.com/tjmlabs/colivara-demo/raw/main/docs/StaffVendorPolicy-Jan2019.pdf",
"filename": "docs/StaffVendorPolicy-Jan2019.pdf",
},
]
# Downloading the files into the docs/ folder
def download_file(url, local_filename):
response = requests.get(url)
if response.status_code == 200:
os.makedirs("docs", exist_ok=True)
with open(local_filename, "wb") as f:
f.write(response.content)
print(f"Successfully downloaded: {local_filename}")
else:
print(f"Failed to download: {url}")
for file in files:
download_file(file["url"], file["filename"])
3
Upload and Process the documents
def sync_documents():
documents_dir = Path("docs")
files = list(documents_dir.glob("**/*"))
for file in files:
with open(file, "rb") as f:
file_content = f.read()
encoded_content = base64.b64encode(file_content).decode("utf-8")
rag_client.upsert_document(
name=file.name,
document_base64=encoded_content,
collection_name="openrouter-demo",
wait=True,
)
print(f"Upserted: {file.name}")
sync_documents()
3. Create the Context
def get_context(query):
results = rag_client.search(query=query, collection_name="openrouter-demo", top_k=3)
results = results.results
context = []
for result in results:
base64 = result.img_base64
if "data:image" not in base64:
base64 = f"data:image/png;base64,{base64}"
context.append(base64)
return context
query = "What is the work from home policy?"
context = get_context(query)
4. Create a Client with your integrated LLM Framework
5. Run your RAG query and Generate the answer
Last updated
Was this helpful?