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
Metadata
Release files for dastavej-rag 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dastavej_rag-0.1.0.tar.gz | 11.5 kB | Without provenance | Details for dastavej_rag-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dastavej_rag-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for dastavej_rag-0.1.0-py3-none-any.whl |
Total release size: 22.2 kB
Release files / dastavej_rag-0.1.0.tar.gz
| Download URL | dastavej_rag-0.1.0.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e8257088da2936e59ae1dfaec4b2ebdb6a0d0b98f323d87c56947ae71a79366d
|
|
BLAKE2b-256 checksum How to use checksums |
aa302f154e6b8ea2ab536e9495e9272ad74d75f16489a0cc8d5ebfdda47a0e5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / dastavej_rag-0.1.0-py3-none-any.whl
| Download URL | dastavej_rag-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2929ca930815550a5dcc80e86c0423cf4f3be161c71cc29eaef822e601174cc
|
|
BLAKE2b-256 checksum How to use checksums |
308a75ae46033e60d3cb39db55592e2460b79ea258a51c2f74e6c5d81ebcd7d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for dastavej-rag 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.