Metadata-Version: 2.5
Name: turkrag
Version: 0.1.0
Summary: Turkish-aware chunking, stemming and retrieval for RAG pipelines, plus an end-to-end Turkish RAG benchmark.
Project-URL: Homepage, https://github.com/AbuzerHarunOzarslan/turkrag
Project-URL: Documentation, https://abuzerharunozarslan.github.io/turkrag/
Project-URL: Repository, https://github.com/AbuzerHarunOzarslan/turkrag
Project-URL: Issues, https://github.com/AbuzerHarunOzarslan/turkrag/issues
Project-URL: Changelog, https://github.com/AbuzerHarunOzarslan/turkrag/blob/main/CHANGELOG.md
Author: Abuzer Harun Özarslan
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: benchmark,bm25,chunking,nlp,rag,retrieval,stemming,turkish
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Natural Language :: Turkish
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Text Processing :: Linguistic
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: numpy>=1.24
Requires-Dist: rank-bm25>=0.2.2
Requires-Dist: snowballstemmer>=2.2
Provides-Extra: all
Requires-Dist: huggingface-hub>=0.23; extra == 'all'
Requires-Dist: langchain-core>=0.3; extra == 'all'
Requires-Dist: langchain-text-splitters>=0.3; extra == 'all'
Requires-Dist: llama-index-core>=0.10; extra == 'all'
Requires-Dist: pyarrow>=14; extra == 'all'
Requires-Dist: pyyaml>=6.0; extra == 'all'
Requires-Dist: sentence-transformers>=2.7; extra == 'all'
Requires-Dist: setuptools<81,>=65; extra == 'all'
Requires-Dist: zemberek-python>=0.2.3; extra == 'all'
Provides-Extra: bench
Requires-Dist: huggingface-hub>=0.23; extra == 'bench'
Requires-Dist: pyarrow>=14; extra == 'bench'
Requires-Dist: pyyaml>=6.0; extra == 'bench'
Requires-Dist: sentence-transformers>=2.7; extra == 'bench'
Provides-Extra: langchain
Requires-Dist: langchain-core>=0.3; extra == 'langchain'
Requires-Dist: langchain-text-splitters>=0.3; extra == 'langchain'
Provides-Extra: llamaindex
Requires-Dist: llama-index-core>=0.10; extra == 'llamaindex'
Provides-Extra: vector
Requires-Dist: sentence-transformers>=2.7; extra == 'vector'
Provides-Extra: zemberek
Requires-Dist: setuptools<81,>=65; extra == 'zemberek'
Requires-Dist: zemberek-python>=0.2.3; extra == 'zemberek'
Description-Content-Type: text/markdown

# TürkRAG

[![CI](https://github.com/AbuzerHarunOzarslan/turkrag/actions/workflows/ci.yml/badge.svg)](https://github.com/AbuzerHarunOzarslan/turkrag/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/turkrag.svg)](https://pypi.org/project/turkrag/)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#katkıcılar--contributors)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

**Türkçe RAG sistemleri için arama kalitesi katmanı ve uçtan uca benchmark.**
*A Turkish-aware retrieval layer and end-to-end benchmark for RAG systems.*

[Türkçe](#türkçe) · [English](#english)

---

## Türkçe

TürkRAG; LangChain ve LlamaIndex'in **yerini almaz**, onların üzerine eklenen Türkçe'ye özel bir katmandır.

| Sorun | TürkRAG çözümü |
|---|---|
| Genel bölücüler `Dr.`, `vb.`, `T.C.` gibi kısaltmalarda cümleyi yanlış keser | Türkçe kısaltma sözlüklü cümle bölücü, cümle sınırını asla bölmeyen chunker'lar |
| BM25 `kitaplarımızdan` ile `kitap`ı eşleştiremez | Kök tabanlı BM25 (Snowball, isteğe bağlı Zemberek) |
| `I`/`ı`, `İ`/`i` dönüşümü ve şapkalı harfler eşleşmeyi bozar | Türkçe'ye uygun normalizasyon |
| Chunking × kök bulucu × arama × embedding kombinasyonlarını ölçen açık benchmark yok | `turkrag-bench` ve [LEADERBOARD](bench/LEADERBOARD.md) |

### Kurulum

```bash
pip install turkrag                 # çekirdek: text, chunking, stem, BM25
pip install "turkrag[vector]"       # + sentence-transformers ile vektör arama
pip install "turkrag[langchain]"    # + LangChain entegrasyonu
pip install "turkrag[bench]"        # + benchmark CLI
```

### Hızlı başlangıç

```python
from turkrag.chunking import SentenceChunker
from turkrag.retrieval import HybridRetriever

chunks = SentenceChunker(max_chars=800, overlap_sentences=1).split(metin)
retriever = HybridRetriever.from_texts(
    chunks, embedding_model="intfloat/multilingual-e5-small", stemmer="snowball"
)
sonuclar = retriever.search("Türkiye'nin en uzun nehri hangisidir?", k=5)
```

### İlk sonuçlar / First results

TurHistQuAD (1.024 soru), belge düzeyinde nDCG@10, CPU. Farklar eşli bootstrap testiyle sınandı (10.000 örnek). 24 karşılaştırmanın hepsine Holm düzeltmesi uygulandı. Parantez içindeki %95 güven aralığı düzeltilmemiş aralıktır. Bu yüzden aralığı 0'ı dışlayan bazı satırlar da, düzeltmeden sonra "fark yok" olarak işaretlendi. Ayrıntılar: [FINDINGS](bench/FINDINGS.md) · tüm satırlar: [LEADERBOARD](bench/LEADERBOARD.md).
*Paired bootstrap, 10,000 resamples. "Significant" means Holm-adjusted p < 0.05 over all 24 comparisons; the bracketed 95% CI is uncorrected.*

| Karşılaştırma / Comparison | Fark / Difference (nDCG@10) | Sonuç / Result |
|---|---:|---|
| Cümle tabanlı parçalama vs bütün belge (BM25) / sentence chunking vs whole documents | +0.083 [+0.072, +0.094] | **anlamlı / significant** |
| Parçalama vs bütün belge (vektör, e5-base) / chunking vs whole documents (vector) | +0.064 [+0.054, +0.075] | **anlamlı / significant** |
| BM25 + kök bulma vs kök bulmasız (3 kök bulucu × 4 chunker) / stemming vs none | +0.016 … +0.035 | **12/12 anlamlı / significant** |
| multilingual-e5-base vs bert-base-turkish-nli-stsb (vektör) | +0.114 [+0.101, +0.128] | **anlamlı / significant** |
| multilingual-e5-base vs multilingual-e5-small (vektör) | +0.015 [+0.008, +0.022] | **anlamlı / significant** |
| Zemberek vs Snowball (BM25) | +0.009 [+0.003, +0.017] | fark yok / no difference |
| Önek vs Snowball (BM25) / prefix vs Snowball | +0.003 [−0.005, +0.010] | fark yok / no difference |
| Cümle örtüşmesi / sentence overlap (sentence-300-1 vs 300-0) | +0.002 [−0.001, +0.005] | fark yok / no difference |
| En iyi hibrit vs en iyi vektör / best hybrid vs best vector (0.573 vs 0.564) | +0.009 [+0.001, +0.016] | fark yok / no difference |
| En iyi vektör vs en iyi BM25 / best vector vs best BM25 (0.564 vs 0.553) | +0.011 [+0.000, +0.022] | fark yok / no difference |

Kısaca, bu veride parçalama, kök bulma ve model seçimi fark yaratıyor; hibrit arama ve kök bulucunun türü ise fark yaratmıyor. Kök bulmalı BM25 (sorgu başına 2.8 ms) e5-base ile vektör aramayla (57 ms) aynı düzeyde.
*In short: chunking, stemming and model choice matter; hybrid search and the choice of stemmer make no measurable difference on this data. Stemmed BM25 (2.8 ms/query) is on par with e5-base vector search (57 ms/query).*

**Sınırlılıklar / Limitations:**
- Tek veri kümesi (tarih ve teknoloji metinleri). *Single dataset.*
- Her sorunun iki ilgili belgesinden biri birkaç kelimelik kısa cevap metni; bu, kelime eşleşmesini kayırabilir. *One relevant document per query is a short answer string, which may favour lexical matching.*
- Yalnızca retrieval ölçüldü. Dört açık model CPU'da çalıştırıldı; BM25 ve RRF parametreleri ayarlanmadı. *Retrieval only, four open models on CPU, untuned BM25/RRF parameters.*

### Katkı

İlk katkını 15 dakikada yapabilirsin: [CONTRIBUTING.md](CONTRIBUTING.md) ·
[İlk katkı için uygun işler](docs/good-first-issues.md)

---

## English

TürkRAG does **not** replace LangChain or LlamaIndex; it is a Turkish-specific layer on top of them:
abbreviation-aware sentence splitting, chunkers that never cut a sentence, stem-aware BM25,
Turkish case/circumflex normalization, dense and hybrid (RRF) retrieval, and `turkrag-bench`, an
open benchmark that measures chunker × stemmer × retriever × embedding-model combinations in a full
retrieval pipeline.

```bash
pip install "turkrag[vector]"
```

See the quick start above. Contributions are welcome: [CONTRIBUTING.md](CONTRIBUTING.md).

---

## Katkıcılar / Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tbody>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/AbuzerHarunOzarslan"><img src="https://avatars.githubusercontent.com/AbuzerHarunOzarslan?s=100" width="100px;" alt=""/><br /><sub><b>Abuzer Harun Özarslan</b></sub></a><br /><a href="#code-AbuzerHarunOzarslan" title="Code">💻</a> <a href="#maintenance-AbuzerHarunOzarslan" title="Maintenance">🚧</a></td>
    </tr>
  </tbody>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

## Lisans / License

[Apache-2.0](LICENSE)
