ragit
RAG toolkit for Python. Document loading, chunking, vector search, LLM integration.
Installation
pip install ragit
Quick Start
You must provide an embedding source: custom function, Ollama, or any provider.
Custom Embedding Function
from ragit import RAGAssistant
def my_embed(text: str) -> list[float]:
# Use any embedding API: OpenAI, Cohere, HuggingFace, etc.
return embedding_vector
assistant = RAGAssistant("docs/", embed_fn=my_embed)
results = assistant.retrieve("search query")
With LLM for Q&A
def my_embed(text: str) -> list[float]:
return embedding_vector
def my_generate(prompt: str, system_prompt: str = "") -> str:
return llm_response
assistant = RAGAssistant("docs/", embed_fn=my_embed, generate_fn=my_generate)
answer = assistant.ask("How does authentication work?")
With Ollama (nomic-embed-text)
from ragit import RAGAssistant
from ragit.providers import OllamaProvider
# Uses nomic-embed-text for embeddings (768d)
assistant = RAGAssistant("docs/", provider=OllamaProvider())
results = assistant.retrieve("search query")
Core API
assistant = RAGAssistant(
documents, # Path, list of Documents, or list of Chunks
embed_fn=..., # Embedding function: (str) -> list[float]
generate_fn=..., # LLM function: (prompt, system_prompt) -> str
provider=..., # Or use a provider instead of functions
chunk_size=512,
chunk_overlap=50
)
results = assistant.retrieve(query, top_k=3) # [(Chunk, score), ...]
context = assistant.get_context(query, top_k=3) # Formatted string
answer = assistant.ask(question, top_k=3) # Requires generate_fn/LLM
code = assistant.generate_code(request) # Requires generate_fn/LLM
Index Persistence
Save and load indexes to avoid re-computing embeddings:
# Save index to disk
assistant.save_index("./my_index")
# Load index later (much faster than re-indexing)
loaded = RAGAssistant.load_index("./my_index", provider=OllamaProvider())
results = loaded.retrieve("query")
Thread Safety
RAGAssistant is thread-safe. Multiple threads can safely read while another writes:
import threading
assistant = RAGAssistant("docs/", provider=OllamaProvider())
# Safe: concurrent reads and writes
threading.Thread(target=lambda: assistant.retrieve("query")).start()
threading.Thread(target=lambda: assistant.add_documents([new_doc])).start()
Resource Management
Use context managers for automatic cleanup:
from ragit.providers import OllamaProvider
with OllamaProvider() as provider:
response = provider.generate("Hello", model="llama3")
# Session automatically closed
Document Loading
from ragit import load_text, load_directory, chunk_text
doc = load_text("file.md")
docs = load_directory("docs/", "*.md")
chunks = chunk_text(text, chunk_size=512, chunk_overlap=50, doc_id="id")
Hyperparameter Optimization
from ragit import RagitExperiment, Document, BenchmarkQuestion
def my_embed(text: str) -> list[float]:
return embedding_vector
def my_generate(prompt: str, system_prompt: str = "") -> str:
return llm_response
docs = [Document(id="1", content="...")]
benchmark = [BenchmarkQuestion(question="...", ground_truth="...")]
experiment = RagitExperiment(
docs, benchmark,
embed_fn=my_embed,
generate_fn=my_generate
)
results = experiment.run(max_configs=20)
print(results[0]) # Best config
License
Apache-2.0 - RODMENA LIMITED
Metadata
Release files for ragit 0.12.2
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 |
|---|---|---|---|---|
| ragit-0.12.2.tar.gz | 51.6 kB | Without provenance | Details for ragit-0.12.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ragit-0.12.2-py3-none-any.whl | Python 3 | none | any | Details for ragit-0.12.2-py3-none-any.whl |
Total release size: 109.9 kB
Release files / ragit-0.12.2.tar.gz
| Download URL | ragit-0.12.2.tar.gz |
|---|---|
| Size | 51.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d15f7a799066d5986d33aeef0dbd519d55c615d4379f073bb8bd6ea00995d8ea
|
|
BLAKE2b-256 checksum How to use checksums |
2360e92f0bb4d8c5c2ec158d5d7641d0606df3d581f27860e5c1fdc18aa66f26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Release files / ragit-0.12.2-py3-none-any.whl
| Download URL | ragit-0.12.2-py3-none-any.whl |
|---|---|
| Size | 58.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d54c3f28140f51216a0554e2763fad2c0f319354ae93f7700295951be5b2f835
|
|
BLAKE2b-256 checksum How to use checksums |
ff8103be61e465881766596f9bd19043ae8f16fd5c4c301f150692a2b5b4917f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Security for ragit 0.12.2
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.