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
- Upload - Documents are parsed, chunked, and stored as vectors
- Search - Queries are converted to vectors and matched against documents
- Retrieve - Most relevant chunks are returned with similarity scores
- Generate - AI uses retrieved context to answer your question
Benefits
| Feature | Without RAG | With RAG |
|---|---|---|
| Access to your data | No | Yes |
| Accurate answers | Limited | Yes |
| Source citations | No | Yes |
| Up-to-date knowledge | No | Yes |
Use Cases
| Use Case | Description |
|---|---|
| Documentation | Product docs, API references, user guides |
| Knowledge Base | Internal policies, procedures, FAQs |
| Customer Support | Support articles, troubleshooting guides |
| Research | Papers, reports, analysis documents |
| Legal | Contracts, 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
| Format | Extension | Notes |
|---|---|---|
| Text | .txt | Plain text files |
| Markdown | .md | Markdown documentation |
.pdf | PDF documents | |
| Word | .docx | Microsoft Word |
| JSON | .json | Structured data |
| HTML | .html | Web pages |
Document Processing Pipeline
When you upload a document:
- Parse - Extract text from file
- Chunk - Split into smaller pieces (500-1000 tokens)
- Embed - Convert chunks to vectors
- 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
- Create Collections - Set up document collections
- Upload Documents - Add documents to your knowledge base
- Search Documents - Find relevant information
- Examples - See RAG in action