Skip to main content

RAG - Document Knowledge Base

Store, search, and retrieve documents to give AI access to your knowledge.

What You'll Learn​

  • Overview - What RAG is and how it works
  • Collections - Create and manage document collections
  • Uploading - Upload documents to your knowledge base
  • Searching - Search documents with semantic queries
  • Managing - List, view, and delete documents
  • Examples - Integration examples

Overview​

RAG (Retrieval-Augmented Generation) combines your documents with AI. It searches your knowledge base and provides relevant context to the AI.

How RAG Works​

  1. Upload - Documents are parsed, chunked, and stored as vectors
  2. Search - Queries are converted to vectors and matched against documents
  3. Retrieve - Most relevant chunks are returned with similarity scores
  4. Generate - AI uses retrieved context to answer your question

Benefits​

FeatureWithout RAGWith RAG
Access to your dataNoYes
Accurate answersLimitedYes
Source citationsNoYes
Up-to-date knowledgeNoYes

Use Cases​

Use CaseDescription
DocumentationProduct docs, API references, user guides
Knowledge BaseInternal policies, procedures, FAQs
Customer SupportSupport articles, troubleshooting guides
ResearchPapers, reports, analysis documents
LegalContracts, regulations, case law

Quick Example​

# Upload a document
curl -X POST http://localhost/api/v1/rag/upload \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@user_guide.pdf" \
-F "collection_name=documentation"

# Search documents
curl -X POST http://localhost/api/v1/rag/search \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"collection_name": "documentation",
"query": "How do I reset my password?",
"top_k": 3
}'

Supported File Formats​

FormatExtensionNotes
Text.txtPlain text files
Markdown.mdMarkdown documentation
PDF.pdfPDF documents
Word.docxMicrosoft Word
JSON.jsonStructured data
HTML.htmlWeb pages

Document Processing Pipeline​

When you upload a document:

  1. Parse - Extract text from file
  2. Chunk - Split into smaller pieces (500-1000 tokens)
  3. Embed - Convert chunks to vectors
  4. Store - Save vectors in vector database

RAG in Action​

import requests

# Upload document
with open("product_docs.pdf", "rb") as f:
response = requests.post(
"http://localhost/api/v1/rag/upload",
headers={"Authorization": "Bearer YOUR_API_KEY"},
files={"file": f},
data={"collection_name": "docs"}
)
print(f"Uploaded: {response.json()['document_id']}")

# Search documents
response = requests.post(
"http://localhost/api/v1/rag/search",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={
"collection_name": "docs",
"query": "How to configure API keys?",
"top_k": 3
}
)

results = response.json()["results"]
for result in results:
print(f"Score: {result['score']:.2f}")
print(f"Content: {result['content'][:100]}...\n")

Next Steps​