Skip to main content

Production-oriented Python framework for building RAG services on top of FastAPI.

Project description

SyRAG logo

SyRAG

Build typed, production-oriented RAG services with a FastAPI-style developer experience.

PyPI Python versions CI Docs License

SyRAG is a Python framework for building Retrieval-Augmented Generation services with explicit pipeline contracts, typed request/response models, and production-facing defaults on top of FastAPI.

It is designed for teams that want RAG APIs with clean provider boundaries, OpenAPI docs, request context, observability, guardrails, and testable local development without committing their whole application to a single orchestration framework.

Highlights

  • FastAPI-style @app.ingest(...) and @app.query(...) route decorators.
  • Typed schemas for ingest, retrieval, generation, citations, usage, and errors.
  • Protocol-first extension points for chunkers, embedders, vector stores, retrieval strategies, prompt assembly, generation policies, LLMs, hooks, rate limiters, and safety guards.
  • Optional integrations for OpenAI, Google, Chroma, FAISS, LangChain, and LlamaIndex.
  • Development/test providers and testing helpers for reliable local and CI workflows.
  • OpenAPI output, structured logging, and OpenTelemetry-compatible tracing.

Supported Python versions: 3.12+.

Installation

Core package:

pip install syrag

Optional integrations:

pip install "syrag[chroma]"
pip install "syrag[faiss]"
pip install "syrag[google]"
pip install "syrag[langchain]"
pip install "syrag[llamaindex]"
pip install "syrag[openai]"
pip install "syrag[testing]"
pip install "syrag[server]"
pip install "syrag[all]"

Quick Start

Install the runtime integrations used in this example:

pip install "syrag[chroma,openai,server]"

Set OPENAI_API_KEY in your environment before starting the app.

Create main.py:

import os
from pathlib import Path

from syrag import (
    SyRAG,
    ChromaVectorStore,
    IngestRequest,
    OpenAIEmbedder,
    OpenAILLM,
    QueryRequest,
    Settings,
)

app = SyRAG(
    title="Support Bot",
    version="0.2.1",
    description="Internal support assistant",
    settings=Settings(),
)

SUPPORT_COLLECTION = "support"

embedder = OpenAIEmbedder(
    api_key=os.environ["OPENAI_API_KEY"],
    model="text-embedding-3-small",
)
vector_store = ChromaVectorStore(
    path=Path(".syrag/chroma"),
    collection_name="support_docs",
)
llm = OpenAILLM(api_key=os.environ["OPENAI_API_KEY"], model="gpt-4.1-mini")


@app.ingest("/ingest", embedder=embedder, vector_store=vector_store)
async def ingest(request: IngestRequest) -> IngestRequest:
    """Normalize incoming documents before they enter the ingest pipeline."""
    return request.model_copy(
        update={
            "collection": request.collection or SUPPORT_COLLECTION,
            "metadata": {"source": "api", **request.metadata},
        }
    )


@app.query("/query", embedder=embedder, vector_store=vector_store, llm=llm)
async def query(request: QueryRequest) -> QueryRequest:
    """Apply route-level retrieval defaults before generation."""
    return request.model_copy(
        update={
            "collection": request.collection or SUPPORT_COLLECTION,
            "top_k": min(request.top_k, 5),
        }
    )

Serve the app with any ASGI server. With the server extra installed:

uvicorn main:app.api --reload

The framework exposes:

  • POST /ingest
  • POST /query
  • GET /health
  • OpenAPI docs at /docs

Ingest a document:

curl -X POST http://127.0.0.1:8000/ingest \
  -H "content-type: application/json" \
  -d '{"documents":["SyRAG builds typed RAG services."],"collection":"demo"}'

Query it:

curl -X POST http://127.0.0.1:8000/query \
  -H "content-type: application/json" \
  -d '{"query":"What does SyRAG build?","collection":"demo","top_k":1}'

Extension Points

SyRAG keeps the pipeline explicit. You can swap or extend:

  • Chunker
  • Embedder
  • VectorStore
  • RetrievalStrategy
  • PromptAssembler
  • GenerationPolicy
  • LLM
  • RequestContextHook
  • AuthHook
  • RateLimiter
  • SafetyGuard

First-Party Providers

Core:

  • InMemoryEmbedder
  • InMemoryVectorStore
  • InMemoryLLM
  • PassThroughChunker
  • SQLiteVectorStore

InMemoryEmbedder, InMemoryVectorStore, and InMemoryLLM are development/test utilities. They are not intended as production embedding, retrieval, or generation backends.

Optional chroma extra:

  • ChromaVectorStore

Optional faiss extra:

  • FAISSVectorStore

Optional google extra:

  • GoogleEmbedder
  • GoogleLLM

Optional openai extra:

  • OpenAIEmbedder
  • OpenAILLM

Observability And Operations

SyRAG includes:

  • structured error responses with stage information
  • request-scoped RequestContext with request IDs and tenant IDs
  • StructuredLogging and JSONLogFormatter
  • OpenTelemetryTracing built on the OpenTelemetry API package
  • request throttling via InMemoryRateLimiter
  • payload validation via DefaultSafetyGuard

Testing

Install the testing extra to use:

  • create_test_app(...)
  • create_test_client(...)
  • seed_documents(...)
  • fake providers such as FakeEmbedder, FakeVectorStore, and FakeLLM

Docs

Build the docs locally with MkDocs Material:

uv run --group docs mkdocs serve

Examples

Cookbook

Full example scripts live in examples/integrations.

Community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

syrag-0.2.1.tar.gz (330.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

syrag-0.2.1-py3-none-any.whl (57.7 kB view details)

Uploaded Python 3

File details

Details for the file syrag-0.2.1.tar.gz.

File metadata

  • Download URL: syrag-0.2.1.tar.gz
  • Upload date:
  • Size: 330.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for syrag-0.2.1.tar.gz
Algorithm Hash digest
SHA256 629b42bc576aef2efef51c386746b6ab325a26f0aaf1b0119273982197571b8c
MD5 98c47cb32e96f87fd4e1acb9b8afc810
BLAKE2b-256 9990ee6d0d209f2a46b0d4d0849d415ca1d5f957f2844bbb5f0bf5cf110f1e42

See more details on using hashes here.

Provenance

The following attestation bundles were made for syrag-0.2.1.tar.gz:

Publisher: publish.yml on a-marzoug/syrag

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file syrag-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: syrag-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 57.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for syrag-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ecc8d4c3d517e8c83a77ba37b2afa66452e570573349911bf4d2040fdb60122
MD5 b33f14dedef7014a033c6c361ae329b7
BLAKE2b-256 a81cf05054d478ba2dd43580abb0c4b6210a48adf2af7bb34621383f39ca9f8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for syrag-0.2.1-py3-none-any.whl:

Publisher: publish.yml on a-marzoug/syrag

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page