A Python library for Retrieval-Augmented Generation (RAG) capabilities in LLM applications.
Project description
fabricatio-rag
Abstract framework for building Retrieval-Augmented Generation (RAG) pipelines on top of Fabricatio's agent architecture. Provides typed base classes, document models, and workflow actions for embedding, storing, retrieving, and reranking documents.
Requires Python 3.12+.
Installation
pip install fabricatio[rag]
# or
uv pip install fabricatio[rag]
Key Components
RAG Base Class (RAG)
Type-parameterized abstract class inheriting UseEmbedding, UseReranker, and UseLLM from fabricatio-core.
Defines the core RAG contract that concrete implementations must fulfill:
add_document(data, config)— embed and store documentsafetch_document(query, config)— retrieve documents by semantic similarityarefined_query(question, **kwargs)— refine user queries via a configurable template before retrievalarank_documents(query, documents, **kwargs)— rerank previously retrieved documents by relevance
Built-in refinement uses TEMPLATE_MANAGER.render_template with the template named in RagConfig.refined_query_template
(default: "built-in/refined_query").
from fabricatio_rag.capabilities.rag import RAG, RAGConfigBase
from fabricatio_rag.models.document import StoredDocumentModel, SearchedDocumentModel
class MyRAG(
RAG[MyStoredDoc, MySearchedDoc, MyAddConfig, MyFetchConfig]
):
async def add_document(self, data, config=None):
# embed with self.aembedding(...), store in vector db
...
async def afetch_document(self, query, config=None):
# embed query, search vector db, return results
...
Document Models (StoredDocumentModel, SearchedDocumentModel)
Generic abstract base classes for document representations.
StoredDocumentModel[ST] extends Base and Vectorizable. Key methods:
prepare_insertion(vector) -> ST— produce a database-ready record from an embedding vectorfrom_txt_files(files, chunk_size, overlap) -> List[Self]— chunk text files using the Rust-backedsplit_into_chunks, creating one model instance per chunkwith_text_chunk(chunk) -> Self— create an instance from a single text chunk (subclass must implement)
SearchedDocumentModel[SD] extends Base and AsPrompt. Key methods:
from_raw(raw) -> Self— construct from raw database resultas_prompt() -> str— render as prompt text (fromAsPromptmixin)
from fabricatio_rag.models.document import StoredDocumentModel, SearchedDocumentModel
class MyStoredDoc(StoredDocumentModel[dict]):
content: str
def prepare_insertion(self, vector):
return {"text": self.content, "vector": vector}
@classmethod
def with_text_chunk(cls, chunk):
return cls(content=chunk)
class MySearchedDoc(SearchedDocumentModel[dict]):
content: str
@classmethod
def from_raw(cls, raw):
return cls(content=raw["text"])
Workflow Actions (StoreTextFile, StoreDocuments)
Ready-to-use Action subclasses that bridge the Fabricatio workflow engine with RAG storage.
StoreTextFile — ingests a list of Path objects, chunks them according to chunk_size (default 512) and
chunk_overlap_ratio (default 0.3), then stores the resulting chunks via add_document.
StoreDocuments — stores pre-built model instances directly, without any chunking step.
Both accept an optional store_config for passing configuration to the underlying add_document call.
from fabricatio_rag.actions.db import StoreTextFile
class MyStoreAction(StoreTextFile[MyStoredDoc, MySearchedDoc, MyAddConfig, MyFetchConfig]):
store_model = MyStoredDoc
chunk_size = 1024
chunk_overlap_ratio = 0.2
store_config = MyAddConfig(collection="docs")
Configuration (RagConfig)
Dataclass loaded from Fabricatio's configuration system under the "rag" section.
| Field | Default | Description |
|---|---|---|
refined_query_template |
"built-in/refined_query" |
Template name for query refinement |
Access via fabricatio_rag.config.rag_config.
Package Structure
fabricatio-rag/
├── python/fabricatio_rag/
│ ├── capabilities/ - RAG abstract base class and config
│ ├── actions/ - StoreTextFile, StoreDocuments workflow actions
│ ├── models/ - StoredDocumentModel, SearchedDocumentModel
│ ├── workflows/ - Workflow definitions (extend here)
│ ├── config.py - RagConfig dataclass
│ └── __init__.py
└── pyproject.toml
Dependencies
fabricatio-core— LLM routing, embedding, reranking, event system, workflow engine, and Rust text-chunking utilities
License
MIT — see LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fabricatio_rag-0.6.0-py3-none-any.whl.
File metadata
- Download URL: fabricatio_rag-0.6.0-py3-none-any.whl
- Upload date:
- Size: 24.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16d2dbe1aee94b48ecf035dff8599701d440de505e287afdb22aad6526e70ead
|
|
| MD5 |
0fb79b8bb3e8002fed82ca0a23df6b1a
|
|
| BLAKE2b-256 |
4662a430a752b65fa975a682773028d621e733b9dedabaa849da8d1577460428
|