Skip to main content

Pydantic AI RAG Stack

pydantic-ai-ragstack is a robust and structured framework designed for Retrieval Augmented Generation (RAG) systems. It leverages Python's pydantic library to enforce strict data schemas across the entire document ingestion, embedding, storage, and retrieval pipeline. This ensures high reliability and predictability when building AI applications based on proprietary knowledge bases.

🚀 Features

  • Structured Data Modeling: Uses Pydantic models (Document, DocumentPage, etc.) to define explicit schemas for all data components (metadata, content, images).
  • End-to-End Ingestion Pipeline: Handles document loading, chunking, image extraction, and metadata enrichment.
  • Vector Store Integration: Manages interaction with various vector databases (pydantic_ai_ragstack/vectorstore.py).
  • Advanced Retrieval: Includes capabilities for content re-ranking (pydantic_ai_ragstack/reranker.py) to improve search relevance.

🛠️ Installation

This project requires Python 3.8+ and several dependencies (e.g., LangChain, PyMuPDF, vector store clients).

# Assuming requirements.txt exists or needs manual installation
pip install -r requirements.txt

📂 Project Structure Overview

The core logic is organized within the pydantic_ai_ragstack package:

  • models.py: Defines all core data structures (e.g., Document, DocumentPageChunk, SearchResult) using Pydantic models.
  • ingestion.py: Manages the entire lifecycle of ingesting raw documents into structured chunks and vector embeddings.
  • documents.py: Handles document loading and parsing (PDF, etc.).
  • embeddings.py: Manages the generation of vector embeddings for content chunks.
  • retrieval.py: Contains logic for querying the vector store and retrieving relevant documents/chunks.
  • vectorstore.py: Abstract layer for interacting with underlying vector databases (e.g., Chroma, Pinecone).

🧠 Usage Example: Ingestion and Retrieval Flow

The typical workflow involves three main stages: Load -> Index -> Query.

Step 1: Document Loading & Processing

Raw documents are loaded and parsed into structured Document objects.

from pydantic_ai_ragstack import documents, ingestion
# Assume 'path/to/document.pdf' exists
raw_docs = documents.load("path/to/document.pdf")
structured_data = raw_docs # Contains list[Document]

Step 2: Indexing (Embedding and Storing)

The structured data is chunked, embedded, and stored in the vector store.

from pydantic_ai_ragstack import ingestion
# Assuming an embedding model is configured
status = ingestion.index_documents(structured_data, embedder=MyEmbeddings())

if status == "done":
    print("Indexing complete. Data is ready for retrieval.")

Step 3: Retrieval and Question Answering (RAG)

A query is executed against the indexed documents to retrieve relevant context before generating a final answer using an LLM (not included in this core module).

from pydantic_ai_ragstack import retrieval
# Query the system
query = "What are the main features of the RAG framework?"
search_results = retrieval.search(query, collection_name="my_knowledge_base")

if search_results:
    print("--- Retrieved Context ---")
    for result in search_results:
        print(f"Score: {result.score:.2f}\nContent: {result.content[:100]}...")
    
    # Pass context and original query to an LLM call here

🧪 Testing

To run unit tests, use pytest:

pip install pytest
pytest tests/

Metadata

Release files for pydantic-ai-ragstack 0.1.0

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

Source distribution (sdist)

Source distribution for pydantic-ai-ragstack 0.1.0
File Size Uploaded Provenance Actions
pydantic_ai_ragstack-0.1.0.tar.gz 339.9 kB Without provenance Details for pydantic_ai_ragstack-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-ai-ragstack 0.1.0
File Interpreter ABI Platform Actions
pydantic_ai_ragstack-0.1.0-py3-none-any.whl Python 3 none any Details for pydantic_ai_ragstack-0.1.0-py3-none-any.whl

Total release size: 383.8 kB

Release files / pydantic_ai_ragstack-0.1.0.tar.gz

Download URL pydantic_ai_ragstack-0.1.0.tar.gz
Size 339.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e656672599fae303a8537f8ab0234ac51ca4403baa79a68ecefee72ad8908754
BLAKE2b-256 checksum
How to use checksums
6b6d62ae8912793f46187712c64bf90bd5d0faaf561f14be897f705fc23e017b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pydantic_ai_ragstack-0.1.0-py3-none-any.whl

Download URL pydantic_ai_ragstack-0.1.0-py3-none-any.whl
Size 43.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88966734089a403e480fa58184312120e3b5dbd29e6a4cda97194272d2844ad5
BLAKE2b-256 checksum
How to use checksums
2f288e481f8062f2cb880f3e1c294465b5d6a13912ca4f0f3d5df28021ddef11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for pydantic-ai-ragstack 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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