RAG Pipeline v2.0
Production-grade Retrieval-Augmented Generation pipeline.
Mimari
Sorgu
│
├─► HyDE (Query Expansion)
│ LLM ile varsayımsal belge üret → embed et
│
├─► Hybrid Retrieval
│ Dense (FAISS/BGE-M3) + Sparse (BM25) → RRF Fusion → candidate_k aday
│
├─► Cross-Encoder Reranker (BGE-Reranker-v2-M3)
│ candidate_k → top_k nihai sonuç
│
└─► LLM (vLLM / HuggingFace)
Context + Soru → Yanıt
Kurulum
# Temel kurulum
pip install -e .
# Tüm opsiyonel bağımlılıklarla
pip install -e ".[all]"
# Sadece geliştirme araçları
pip install -e ".[dev]"
Hızlı Başlangıç
# Terminal 1: vLLM sunucusu
vllm serve google/gemma-3-27b-it --dtype bfloat16 --port 8000
# Terminal 2: Pipeline
python main.py
Konfigürasyon
Ayarlar config.py içinde Pydantic Settings ile yönetilir.
Ortam değişkeni veya .env dosyasıyla override edilebilir:
# Ortam değişkeni ile
RAG_TOP_K=10 RAG_USE_HYDE=false python main.py
# .env dosyası ile
echo "RAG_TOP_K=10" >> .env
echo "RAG_USE_HYDE=false" >> .env
python main.py
Tüm Ayarlar
| Değişken | Default | Açıklama |
|---|---|---|
RAG_EMBEDDING_BACKEND |
huggingface |
huggingface veya ollama |
RAG_EMBED_MODEL |
BAAI/bge-m3 |
HuggingFace embedding modeli |
RAG_LLM_BACKEND |
vllm |
vllm veya huggingface |
RAG_VLLM_BASE_URL |
http://localhost:8000/v1 |
vLLM sunucu adresi |
RAG_VLLM_MODEL |
google/gemma-3-27b-it |
LLM model adı |
RAG_USE_RERANKER |
true |
Reranker aktif/pasif |
RAG_RERANKER_MODEL |
BAAI/bge-reranker-v2-m3 |
Reranker modeli |
RAG_USE_HYDE |
true |
HyDE aktif/pasif |
RAG_CHUNK_SIZE |
450 |
Chunk karakter boyutu |
RAG_CHUNK_OVERLAP |
100 |
Chunk overlap |
RAG_CANDIDATE_K |
50 |
Stage 1 aday sayısı |
RAG_TOP_K |
5 |
LLM'e verilecek context sayısı |
RAG_OBS_LOG_PATH |
./obs_log.jsonl |
Observability log dosyası |
Proje Yapısı
rag_project/
├── main.py # Giriş noktası
├── config.py # Merkezi ayar yönetimi
├── pyproject.toml
├── setup.py
├── LICENSE
├── README.md
└── rag_pipeline/
├── __init__.py
├── pipeline.py # Ana RAGPipeline sınıfı
├── chunking/
│ ├── __init__.py
│ └── strategies.py # Fixed / Semantic / Markdown / Paragraph / Router
├── document_loaders/
│ ├── __init__.py
│ └── loaders.py # TXT / PDF / CSV / JSONL / Excel / Word
├── embeddings/
│ ├── __init__.py
│ └── backends.py # HuggingFace / Ollama + LRU cache
├── llms/
│ ├── __init__.py
│ └── backends.py # OpenAI-compat (vLLM) / HuggingFace
├── vector_stores/
│ ├── __init__.py
│ └── faiss_store.py # FAISS disk-persist + metadata filtre
└── retrievers/
├── __init__.py
├── hybrid.py # BM25 + Dense → RRF
├── reranker.py # CrossEncoder reranker
└── query_expansion.py # HyDE
Testler
pip install -e ".[dev]"
pytest
pytest --cov=rag_pipeline --cov-report=term-missing
Observability
Her sorgu obs_log.jsonl dosyasına JSONL formatında loglanır:
{
"ts": "2025-01-01T12:00:00",
"query": "Soru metni",
"expanded_query": "HyDE ile genişletilmiş sorgu",
"n_candidates": 50,
"n_final": 5,
"scores_before": [0.82, 0.79, ...],
"scores_after": [0.94, 0.91, ...],
"latency": {
"hyde_ms": 420,
"retrieve_ms": 85,
"rerank_ms": 210,
"llm_ms": 1840,
"total_ms": 2560
},
"answer_len": 312
}
Bu log dosyasını RAGAS veya LLM-as-judge ile periyodik olarak değerlendirerek pipeline kalitesini takip edebilirsiniz.
Metadata
Release files for rag-pipeline-lib 0.2.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 | |
|---|---|---|---|---|
| rag_pipeline_lib-0.2.0.tar.gz | 23.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rag_pipeline_lib-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 46.7 kB
Release files / rag_pipeline_lib-0.2.0.tar.gz
| Download URL | rag_pipeline_lib-0.2.0.tar.gz |
|---|---|
| Size | 23.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85e4eb6253a1dc3c8d75a6587426963357f4bcb95601463a1b76e47512c81f3f
|
|
BLAKE2b-256 checksum How to use checksums |
81a1e022ceec7182dede060039fef54decb6ff3a97bdeb508578a9701a2138eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / rag_pipeline_lib-0.2.0-py3-none-any.whl
| Download URL | rag_pipeline_lib-0.2.0-py3-none-any.whl |
|---|---|
| Size | 23.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5030b36f2004a9836ae91764d1d95873e8564085c06f5f7bcca09e9bc100d583
|
|
BLAKE2b-256 checksum How to use checksums |
7b8e4264ceea45feec9fbc26c3b30c2b5bd624957be29026d01f511e90bca01f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for rag-pipeline-lib 0.2.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.