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

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.2
File Size Uploaded
ragit-0.12.2.tar.gz 51.6 kB Details

Built distribution (wheel)

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

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

Release history Release notifications | RSS feed

This release

0.12.2 This release

2 release files

0.12.1

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