rag-python 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rag_python/__init__.py +1 -1
- rag_python/cli.py +18 -3
- rag_python/providers/factory.py +4 -1
- rag_python/providers/local_provider.py +34 -0
- {rag_python-0.1.0.dist-info → rag_python-0.2.0.dist-info}/METADATA +7 -3
- {rag_python-0.1.0.dist-info → rag_python-0.2.0.dist-info}/RECORD +10 -9
- {rag_python-0.1.0.dist-info → rag_python-0.2.0.dist-info}/LICENSE +0 -0
- {rag_python-0.1.0.dist-info → rag_python-0.2.0.dist-info}/WHEEL +0 -0
- {rag_python-0.1.0.dist-info → rag_python-0.2.0.dist-info}/entry_points.txt +0 -0
- {rag_python-0.1.0.dist-info → rag_python-0.2.0.dist-info}/top_level.txt +0 -0
rag_python/__init__.py
CHANGED
rag_python/cli.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"""rag-python command-line interface."""
|
|
2
2
|
import argparse
|
|
3
|
+
from dataclasses import replace
|
|
3
4
|
|
|
5
|
+
from . import __version__
|
|
4
6
|
from .client import RAG
|
|
5
7
|
|
|
6
8
|
|
|
@@ -21,9 +23,17 @@ def _build_rag(args: argparse.Namespace) -> RAG:
|
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
def _add_provider_args(parser: argparse.ArgumentParser) -> None:
|
|
24
|
-
parser.add_argument(
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
"--llm-provider",
|
|
28
|
+
default="openai",
|
|
29
|
+
choices=["openai", "azure_openai", "anthropic", "gemini", "ollama"],
|
|
30
|
+
)
|
|
25
31
|
parser.add_argument("--llm-model", default=None)
|
|
26
|
-
parser.add_argument(
|
|
32
|
+
parser.add_argument(
|
|
33
|
+
"--embedding-provider",
|
|
34
|
+
default="openai",
|
|
35
|
+
choices=["openai", "azure_openai", "ollama", "local"],
|
|
36
|
+
)
|
|
27
37
|
parser.add_argument("--embedding-model", default=None)
|
|
28
38
|
parser.add_argument("--ollama-base-url", default=None)
|
|
29
39
|
parser.add_argument("--azure-endpoint", default=None)
|
|
@@ -39,6 +49,7 @@ def main() -> None:
|
|
|
39
49
|
prog="rag-python",
|
|
40
50
|
description="rag-python — modular RAG with query rewriting, reranking, guardrails, and multi-LLM support.",
|
|
41
51
|
)
|
|
52
|
+
parser.add_argument("--version", action="version", version=f"rag-python {__version__}")
|
|
42
53
|
sub = parser.add_subparsers(dest="command", required=True)
|
|
43
54
|
|
|
44
55
|
ing = sub.add_parser("ingest", help="Ingest files/folders into the vector store")
|
|
@@ -63,7 +74,11 @@ def main() -> None:
|
|
|
63
74
|
if args.command == "query":
|
|
64
75
|
rag = _build_rag(args)
|
|
65
76
|
question = " ".join(args.question)
|
|
66
|
-
|
|
77
|
+
search = replace(
|
|
78
|
+
rag.config.search,
|
|
79
|
+
retriever="vector" if args.no_multi_query else "multi_query",
|
|
80
|
+
)
|
|
81
|
+
ans = rag.query(question, search=search)
|
|
67
82
|
print(ans.text)
|
|
68
83
|
if args.verbose:
|
|
69
84
|
print("\n--- evaluation ---")
|
rag_python/providers/factory.py
CHANGED
|
@@ -9,10 +9,11 @@ from .azure_openai_provider import AzureOpenAIProvider
|
|
|
9
9
|
from .anthropic_provider import AnthropicProvider
|
|
10
10
|
from .gemini_provider import GeminiProvider
|
|
11
11
|
from .ollama_provider import OllamaProvider
|
|
12
|
+
from .local_provider import LocalEmbeddingProvider
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
LLMProviderName = Literal["openai", "azure_openai", "anthropic", "gemini", "ollama"]
|
|
15
|
-
EmbeddingProviderName = Literal["openai", "azure_openai", "ollama"]
|
|
16
|
+
EmbeddingProviderName = Literal["openai", "azure_openai", "ollama", "local"]
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
def make_llm_provider(name: LLMProviderName, **kwargs) -> LLMProvider:
|
|
@@ -49,5 +50,7 @@ def make_embedding_provider(name: EmbeddingProviderName, **kwargs) -> EmbeddingP
|
|
|
49
50
|
)
|
|
50
51
|
if name == "ollama":
|
|
51
52
|
return OllamaProvider(base_url=kwargs.get("base_url") or os.getenv("OLLAMA_BASE_URL", "http://localhost:11434"))
|
|
53
|
+
if name == "local":
|
|
54
|
+
return LocalEmbeddingProvider(model_name=kwargs.get("model") or os.getenv("LOCAL_EMBEDDING_MODEL"))
|
|
52
55
|
raise ValueError(f"Unknown embedding provider: {name}")
|
|
53
56
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Local sentence-transformers embeddings (no API key required)."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
_DEFAULT_MODEL = "all-MiniLM-L6-v2"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class LocalEmbeddingProvider:
|
|
10
|
+
"""Offline embeddings via sentence-transformers."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, model_name: str | None = None) -> None:
|
|
13
|
+
self.default_model = model_name or os.getenv("LOCAL_EMBEDDING_MODEL", _DEFAULT_MODEL)
|
|
14
|
+
self._models: dict[str, object] = {}
|
|
15
|
+
|
|
16
|
+
def _get_model(self, model_name: str):
|
|
17
|
+
if model_name not in self._models:
|
|
18
|
+
try:
|
|
19
|
+
from sentence_transformers import SentenceTransformer
|
|
20
|
+
except ImportError as e:
|
|
21
|
+
raise ImportError(
|
|
22
|
+
"Local embeddings require optional dependencies. "
|
|
23
|
+
"Install with: pip install rag-python[local]"
|
|
24
|
+
) from e
|
|
25
|
+
self._models[model_name] = SentenceTransformer(model_name)
|
|
26
|
+
return self._models[model_name]
|
|
27
|
+
|
|
28
|
+
def embed(self, texts: list[str], *, model: str | None = None) -> list[list[float]]:
|
|
29
|
+
if not texts:
|
|
30
|
+
return []
|
|
31
|
+
model_name = model or self.default_model
|
|
32
|
+
encoder = self._get_model(model_name)
|
|
33
|
+
vectors = encoder.encode(texts, convert_to_numpy=True)
|
|
34
|
+
return [v.tolist() for v in vectors]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: rag-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Production-grade RAG for Python: multi-LLM, query rewriting, reranking, guardrails, and evaluation.
|
|
5
5
|
Author-email: Raghav Singla <04raghavsingla28@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -33,6 +33,8 @@ Requires-Dist: requests>=2.31.0
|
|
|
33
33
|
Provides-Extra: rerank
|
|
34
34
|
Requires-Dist: sentence-transformers>=2.2.0; extra == "rerank"
|
|
35
35
|
Requires-Dist: torch>=2.0.0; extra == "rerank"
|
|
36
|
+
Provides-Extra: local
|
|
37
|
+
Requires-Dist: sentence-transformers>=2.2.0; extra == "local"
|
|
36
38
|
Provides-Extra: anthropic
|
|
37
39
|
Requires-Dist: anthropic>=0.20.0; extra == "anthropic"
|
|
38
40
|
Provides-Extra: gemini
|
|
@@ -43,10 +45,12 @@ Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
|
43
45
|
Requires-Dist: build; extra == "dev"
|
|
44
46
|
Requires-Dist: twine; extra == "dev"
|
|
45
47
|
Provides-Extra: all
|
|
46
|
-
Requires-Dist: rag-python[anthropic,gemini,rerank]; extra == "all"
|
|
48
|
+
Requires-Dist: rag-python[anthropic,gemini,local,rerank]; extra == "all"
|
|
47
49
|
|
|
48
50
|
# rag-python
|
|
49
51
|
|
|
52
|
+
[](https://pypi.org/project/rag-python/)
|
|
53
|
+
[](https://pypi.org/project/rag-python/)
|
|
50
54
|
[](https://www.python.org/downloads/)
|
|
51
55
|
[](LICENSE)
|
|
52
56
|
[](https://github.com/RaghavOG/rag-python)
|
|
@@ -77,7 +81,7 @@ pip install rag-python
|
|
|
77
81
|
# or from source
|
|
78
82
|
pip install -e .
|
|
79
83
|
# with reranking + extra providers
|
|
80
|
-
pip install -e ".[rerank,anthropic,gemini,all]"
|
|
84
|
+
pip install -e ".[rerank,local,anthropic,gemini,all]"
|
|
81
85
|
```
|
|
82
86
|
|
|
83
87
|
---
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
rag_python/__init__.py,sha256=
|
|
1
|
+
rag_python/__init__.py,sha256=4XDhojztA62P_jxiZ0maaVr8UtcVqbcQLjA_MaIZ8X8,834
|
|
2
2
|
rag_python/chunking.py,sha256=P1dbZ8ZY7487MxrWe2cypCiKhzIJ8zBPCTVz20vt8fo,6204
|
|
3
3
|
rag_python/cleaning.py,sha256=fSux4T0pg7Xe_8NUP2pgzuForyRk1i2VPYIXSzRajzs,3193
|
|
4
|
-
rag_python/cli.py,sha256=
|
|
4
|
+
rag_python/cli.py,sha256=Cm7P-ryNrb2m2VEp293KbL2z2U_KSooP50wY044fmh4,3481
|
|
5
5
|
rag_python/client.py,sha256=MhWAm92Ic2FQ1DTej4EhAlT9UoPN-GjxA0xrHIvwNA8,7656
|
|
6
6
|
rag_python/config.py,sha256=Zw8TjQFKRvOUHpIb7kjEb7DtPFoYPzdQyOPzSXTqDcc,1389
|
|
7
7
|
rag_python/document_loaders.py,sha256=izguVJjPq8v4hDWC8wGP2-LwiYUJbVe-DOsIX6n9J9E,2429
|
|
@@ -19,13 +19,14 @@ rag_python/providers/__init__.py,sha256=SjhMvYoA30EY5VUYVXhEGwcmQnIU2tUomcNE0_0N
|
|
|
19
19
|
rag_python/providers/anthropic_provider.py,sha256=dSiCdM4F90jI9w7z_wS10XuVsX-pR733-cAgJHtVV2Q,1493
|
|
20
20
|
rag_python/providers/azure_openai_provider.py,sha256=8SbI7rDzQgvC4ZXP89Q8kjfqeWuBfX1KKgExGLFkmx0,1940
|
|
21
21
|
rag_python/providers/base.py,sha256=M9DYowQvNvRuATaM6944CWovK0awJ0buBmbnQfroJos,593
|
|
22
|
-
rag_python/providers/factory.py,sha256=
|
|
22
|
+
rag_python/providers/factory.py,sha256=O7nYikPOh_LnVgTVIreLQKL-ehIMayr3KXES1wpKpjw,2717
|
|
23
23
|
rag_python/providers/gemini_provider.py,sha256=OZzs1YJQSZituoxS5Gk8yv3jYNIFY1SVovWUu7lz5Z4,1842
|
|
24
|
+
rag_python/providers/local_provider.py,sha256=tgYBNUrs7pKpPebA0tpNhJmtZLwwINuZFqKMyHlymTQ,1332
|
|
24
25
|
rag_python/providers/ollama_provider.py,sha256=DDhDriB6-Ob0r2-M-P3SvIFG37ruDAErtU7LWDK8xh0,1958
|
|
25
26
|
rag_python/providers/openai_provider.py,sha256=oR7rCCaxCtirAVetJrR4oC3UrWySuqLc9kbosydoQAQ,1585
|
|
26
|
-
rag_python-0.
|
|
27
|
-
rag_python-0.
|
|
28
|
-
rag_python-0.
|
|
29
|
-
rag_python-0.
|
|
30
|
-
rag_python-0.
|
|
31
|
-
rag_python-0.
|
|
27
|
+
rag_python-0.2.0.dist-info/LICENSE,sha256=PZ61Z6ve0hBHgztaC1rPgnxQTRXRkeHKASlnKkX2pvc,1079
|
|
28
|
+
rag_python-0.2.0.dist-info/METADATA,sha256=2_E_U0z3lYdjXhHAYRrqqDQaetoIsnUI2BrWL-GErfs,5506
|
|
29
|
+
rag_python-0.2.0.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
|
|
30
|
+
rag_python-0.2.0.dist-info/entry_points.txt,sha256=558Rd4GWV_6mIyqdRSVNE4ZZi0-KdblTZhcMbIn3ryY,51
|
|
31
|
+
rag_python-0.2.0.dist-info/top_level.txt,sha256=SrgudPwkJWfJ3gUn2n-dhrt9vN2XbQcaZ3wLQZed4Z4,11
|
|
32
|
+
rag_python-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|