fastrag#

fastrag — SDK for building RAG chatbots from dynamic sources.

class fastrag.Document(id, source_id, content, step_config_hash='', embedding=None, metadata=<factory>, cached=False)[source]#

Bases: object

A text-based unit processed along the pipeline.

The same type represents a whole parsed document and a chunk of one; metadata and step_config_hash carry lineage rather than a separate subtype per stage.

Parameters:
id#

Unique identifier for this unit, typically a content or configuration hash.

Type:

str

source_id#

Identifier of the originating Source.

Type:

str

content#

Text content of the document or chunk.

Type:

str

step_config_hash#

Hash of the upstream transform’s configuration, used for cache invalidation.

Type:

str

embedding#

Dense vector representation produced by an embedder step.

Type:

list[float] | None

metadata#

Extended metadata tracking lineage, chunk offsets, URL filters, and parser outputs. Reserved keys include source_uri and content_type (the originating Source’s URI and media type) and content_format (a ContentFormat value describing what kind of string content is) — all three stamped by build_document() so no parser can forget them.

Type:

dict[str, Any]

cached#

Whether this instance was served from the cache rather than freshly produced. Runtime-only: never persisted.

Type:

bool

Modules

benchmark

Benchmarking: load a dataset, score a pipeline against it, compare runs.

exceptions

Exception hierarchy.

ingestion

fastrag.ingestion — lazy, event-emitting ingestion pipeline.

lexical_store

fastrag.lexical_store — the read contract for BM25 relevance search.

models

Document: the text-based unit shared across the pipeline and beyond.

normalization

Extensible source-preserving normalization separate from ingestion parsers.

query

Querying: turning retrieved documents and a question into a generated answer.

retrieval

Retrieval: turning one query into the documents that answer it.

serve

Serving: a FastAPI app that persists chats and streams grounded answers.

vector_store

fastrag.vector_store — the pipeline's storage backend, read and written.