Skip to main content

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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ragit 0.12.1
File Size Uploaded
ragit-0.12.1.tar.gz 51.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ragit 0.12.1
File Interpreter ABI Platform
ragit-0.12.1-py3-none-any.whl Python 3 none any Details

Total release size: 109.2 kB

Release files / ragit-0.12.1.tar.gz

Download URL ragit-0.12.1.tar.gz
Size 51.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3ed7f5907c080b46eaa0ef40371dfe9b1d377e7a44da2cd0b5a36ceb893938ef
BLAKE2b-256 checksum
How to use checksums
247cfe9a6d5be5a68d7ad56c7a7ba6e6d04b1beffb333cff7a6ed364b06bc236
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.1-py3-none-any.whl

Download URL ragit-0.12.1-py3-none-any.whl
Size 57.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0667673cd2d776112a849434a3c88beeead8a05624dd1ad88cfef967fd0bc42c
BLAKE2b-256 checksum
How to use checksums
ad9839cdc4e8fe0758eaab631b4f7f4a48474701a9130284a484c9983630de79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release history Release notifications | RSS feed

0.12.2

2 release files

This release

0.12.1 This release

2 release files

0.12.0

2 release files

0.10.1

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page