Skip to main content

The rag-core-api contains the API layer for the RAG template for document retrieval, question answering, knowledge base management in the vector database and more.

Project description

rag-core-api

High-level API layer for the STACKIT RAG-Template. It transforms its own primitives and those from rag-core-lib into a production-ready FastAPI surface, exposing chat, evaluation, and document-management endpoints used by services/rag-backend and the MCP server of the RAG-Template.

Responsibilities

  • Dependency Injection – Compose the dependency-injector container to assemble LLMs, embeddings, vector stores, rerankers, and retrievers from rag-core-lib.
  • API Exposure – Expose production-ready FastAPI routers for chat, evaluation, and information piece management.
  • Chat Orchestration – Provide default LangGraph chat orchestration and evaluation pipelines that downstream services can reuse or override.
  • Knowledge base integration – Manages all interaction with the knowledge base (vector database).

Feature highlights

  • Chat graph built on LangGraph – Default DefaultChatGraph stitches together language detection, question rephrasing, retrieval (with reranking), answer generation, and Langfuse tracing.
  • Evaluation endpoint – Ships a Langfuse + RAGAS evaluator so you can score QA datasets against your RAG stack without custom plumbing.
  • Pluggable components – Replace embedder, vector database, reranker, prompts, or chains via dependency-injector overrides. The defaults target Qdrant + FlashRank but every interface is typed.
  • Consistent models – Pydantic schemas in rag_core_api.models cover request/response payloads for chat, evaluation, and document ingestion.
  • Shared configuration – Reuses rag-core-lib settings so LLMS, embeddings, retries, and Langfuse behave the same way across services.

Installation

pip install rag-core-api

Requires Python 3.13 and rag-core-lib.

Where it fits in the RAG solution

Layer Responsibilities Package
RAG primitives LLMs, embeddings, retry, tracing (shared in multiple libs) rag-core-lib
API assembly (this package) Routers, dependency container, evaluators, graph wiring rag-core-api
Service runtime FastAPI application to customize the API offered by rag-core-api services/rag-backend

Other services (admin backend and MCP server) call the endpoints provided by this package to ingest, delete, and chat with information pieces.

Module tour

  • dependency_container.py – Configures dependency-injector providers. Override registrations here to swap providers or inject fakes for tests.
  • api_endpoints/ & impl/api_endpoints/ – Thin endpoints + abstractions (Chat, InformationPiecesUploader, etc.) that map HTTP verbs to underlying logic.
  • api/ – Core API definitions, mostly created by API-specs and openapi generator.
  • embeddings/ & impl/embeddings/ – Embedding classes + abstractions + embedder type definitions.
  • evaluator/ & impl/evaluator/ – Langfuse + RAGAS evaluator used by /evaluate endpoint.
  • graph/ & impl/graph/ – LangGraph graph + state definitions for chat flows, including language detection, rephrasing, retrieval etc.
  • reranking/ & impl/reranking/ – Reranking logic for selecting most relevant documents.
  • retriever/ & impl/retriever/ – Document retrieval logic.
  • impl/settings/ – Configuration settings for dependency injection container components.
  • mapper/ – Information piece 2 langchain documents mapper.
  • prompt_templates/ – Default LLM prompts for answering, rephrasing, and language detection. Override them via Langfuse or dependency injection.
  • embeddings/ – Thin wrappers that adapt embedder instances from rag-core-lib for retriever usage. They will be removed in v4.
  • utils/ – Shared utility functions and classes.
  • vector_databases/ & impl/vector_databases/ – Interfaces plus default implementations (Qdrant, FlashRank).

Endpoints provided

  • POST /chat/{session_id} – Conversational RAG (streaming and non-streaming depending on transport). Handles language detection, retrieval, and answer generation.
  • POST /evaluate – Runs RAGAS evaluation on supplied question/answer datasets; outputs Langfuse traces and aggregate metrics.
  • POST /information_pieces/upload – Accepts pre-extracted (e.g., from extractor-api-lib) and processed (e.g., from admin-api-lib) documents for ingestion into the vector store.
  • POST /information_pieces/remove – Removes stored information pieces by document identifier from the vector store.

Refer to libs/README.md for in-depth API documentation.

Configuration overview

rag-core-api consumes the same environment variables as rag-core-lib for provider selection (RAG_CLASS_TYPE_LLM_TYPE, EMBEDDER_CLASS_TYPE_EMBEDDER_TYPE, Langfuse keys, retry settings). Additional knobs include:

  • QDRANT_URL, QDRANT_API_KEY, QDRANT_COLLECTION_NAME – passed into the default QdrantDatabase.
  • FLASHRANK_MODEL_NAME – tuner for FlashRank reranker.
  • RAGAS_DATASET_FILENAME, RAGAS_MODEL – control evaluation dataset and LLM.

The Helm chart supplies these values through backend.envs.*. Local development can rely on .env configuration (see repository root documentation).

Typical usage

from rag_core_api.main import app as perfect_rag_app

Delivers a full functional API. See services/rag-backend/main.py and services/rag-backend/container.py, which compose the API with additional middleware, auth, and deployment-specific wiring.

Extending the library

  1. Subclass the relevant interface (e.g., VectorDatabase, Retriever, Chat endpoint).
  2. Register your implementation in the dependency container.
  3. Add pytest-based tests under libs/rag-core-api/tests that exercise the new component via the container.

Because components depend on interfaces defined here, downstream services can swap behavior without modifying the public API surface.

Contributing

Ensure new endpoints or adapters remain thin and defer to rag-core-lib for shared logic. Run poetry run pytest and the configured linters before opening a PR. For further instructions see the Contributing Guide.

License

Licensed under the project license. See the root LICENSE file.

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

rag_core_api-3.4.0.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

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

rag_core_api-3.4.0-py3-none-any.whl (64.2 kB view details)

Uploaded Python 3

File details

Details for the file rag_core_api-3.4.0.tar.gz.

File metadata

  • Download URL: rag_core_api-3.4.0.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.5 Darwin/24.6.0

File hashes

Hashes for rag_core_api-3.4.0.tar.gz
Algorithm Hash digest
SHA256 bc78ce3944de7f98ad233ed6e1fd232070966b4ca7347a6bc010bcc9dc7d8d3f
MD5 8fa21febb5871e2ef5ebacc00e5a10f5
BLAKE2b-256 bef6284ec017ddc0ca9c4bd004d8daf52255c1acee8003efacedef7b785ad77b

See more details on using hashes here.

File details

Details for the file rag_core_api-3.4.0-py3-none-any.whl.

File metadata

  • Download URL: rag_core_api-3.4.0-py3-none-any.whl
  • Upload date:
  • Size: 64.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.5 Darwin/24.6.0

File hashes

Hashes for rag_core_api-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 26321f4c17ebb102ee67dd2d3e6d6568da6e3e4ed120d6c36262fda6508e923c
MD5 8a985a2ed55844b9d1dc63b2d084ba29
BLAKE2b-256 bf4f8e21395fcfb809f548096a2c377a022a94da79394b28c43fc61dcb576134

See more details on using hashes here.

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