Dastavej RAG
A simple Python framework for building multi-user Retrieval-Augmented Generation (RAG) applications.
dastavej-rag provides PDF ingestion, text chunking, embeddings, Qdrant vector storage, user-isolated semantic retrieval, duplicate-document detection, source tracking, and LLM-based question answering.
Features
- PDF ingestion with PyMuPDF
- Plain-text ingestion
- Automatic text chunking with overlap
- Sentence Transformer embeddings
- Qdrant vector storage
- Persistent local vector database
- User-isolated retrieval using
user_id - Duplicate PDF detection using SHA-256
- Semantic similarity search
- Gemini LLM integration
- Custom LLM support
- Source and page tracking
- Document deletion
- User-data deletion
- Structured
RAGResponse - Structured
Sourceobjects
Installation
pip install dastavej-rag
Gemini Setup
Set your Gemini API key:
export GEMINI_API_KEY="your-api-key"
Never commit API keys to source control.
Quick Start
import dastavej_rag as dr
rag = dr.RAG(
llm=dr.GeminiLLM()
)
result = rag.add(
"company_policy.pdf",
user_id="user_123"
)
print(result)
response = rag.ask(
"What is the leave policy?",
user_id="user_123"
)
print(response.answer)
for source in response.sources:
print(source.source)
print(source.page)
print(source.score)
Add Plain Text
rag.add(
"Qdrant is a vector database.",
user_id="user_123"
)
You can also use the explicit API:
rag.add_text(
text="Qdrant is a vector database.",
user_id="user_123"
)
Retrieve Chunks
results = rag.retrieve(
query="What vector database is used?",
user_id="user_123",
top_k=3
)
for result in results:
print(result["text"])
print(result["score"])
Delete a Document
rag.delete_document(
document_id="document-id",
user_id="user_123"
)
Delete User Data
rag.delete_user_data(
user_id="user_123"
)
Custom LLM Providers
You can implement your own provider by extending BaseLLM:
import dastavej_rag as dr
class MyLLM(dr.BaseLLM):
def generate(self, prompt: str) -> str:
# Call your preferred LLM here.
return "Generated answer"
rag = dr.RAG(
llm=MyLLM()
)
This allows Dastavej RAG to work with other LLM providers.
RAG Pipeline
PDF / Text
↓
Text Extraction
↓
Chunking
↓
Embeddings
↓
Qdrant
↓
user_id Filtering
↓
Semantic Retrieval
↓
Context Construction
↓
LLM
↓
RAGResponse
├── answer
└── sources
Multi-User Applications
Every stored chunk contains a user_id.
Retrieval and deletion operations filter using that user_id, allowing applications to logically isolate documents belonging to different users.
Authentication and authorization remain the responsibility of the application using dastavej-rag. Applications should provide a trusted user_id derived from their authenticated user/session rather than trusting arbitrary client input.
Duplicate Detection
PDF files are hashed using SHA-256.
Uploading the same PDF again for the same user returns a duplicate result instead of embedding and storing the document again.
The same document may still be independently stored for another user.
Local Storage
By default, Qdrant data is persisted locally under:
.dastavej_qdrant/
Add this directory to .gitignore.
Development
Install development dependencies:
pip install -e ".[dev]"
Run tests:
python -m pytest -v
Current Version
0.1.0
Dastavej RAG is currently an alpha release.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dastavej_rag-0.1.0.tar.gz.
File metadata
- Download URL: dastavej_rag-0.1.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8257088da2936e59ae1dfaec4b2ebdb6a0d0b98f323d87c56947ae71a79366d
|
|
| MD5 |
c424505ff833ffcd91c10af8b9d40926
|
|
| BLAKE2b-256 |
aa302f154e6b8ea2ab536e9495e9272ad74d75f16489a0cc8d5ebfdda47a0e5d
|
File details
Details for the file dastavej_rag-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dastavej_rag-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2929ca930815550a5dcc80e86c0423cf4f3be161c71cc29eaef822e601174cc
|
|
| MD5 |
fb316694cc0f118b65f6a3ee01e062c8
|
|
| BLAKE2b-256 |
308a75ae46033e60d3cb39db55592e2460b79ea258a51c2f74e6c5d81ebcd7d0
|