Skip to main content

Production-grade RAG: BGE-M3 + FAISS + BM25 + RRF + Reranker + HyDE

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rag_pipeline_lib-0.2.0.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rag_pipeline_lib-0.2.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file rag_pipeline_lib-0.2.0.tar.gz.

File metadata

  • Download URL: rag_pipeline_lib-0.2.0.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for rag_pipeline_lib-0.2.0.tar.gz
Algorithm Hash digest
SHA256 85e4eb6253a1dc3c8d75a6587426963357f4bcb95601463a1b76e47512c81f3f
MD5 c7f50dcb79708272e48c25d62ee7f1c4
BLAKE2b-256 81a1e022ceec7182dede060039fef54decb6ff3a97bdeb508578a9701a2138eb

See more details on using hashes here.

File details

Details for the file rag_pipeline_lib-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rag_pipeline_lib-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5030b36f2004a9836ae91764d1d95873e8564085c06f5f7bcca09e9bc100d583
MD5 9403d1d75b7004ab76da8cb991313747
BLAKE2b-256 7b8e4264ceea45feec9fbc26c3b30c2b5bd624957be29026d01f511e90bca01f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page