Skip to content

Python API

These are the names import lasagna exposes, in lasagna.__all__. The package loads each one on first use, so import lasagna stays fast.

Decorators and registry

Each stage has a decorator with the same name: lasagna.reranker, lasagna.query_enhancer, lasagna.chunker, lasagna.embedder, lasagna.retriever, lasagna.document_processor and lasagna.generator. All take the same arguments and register under the stage they are named for:

import lasagna

@lasagna.reranker                      # name taken from the function
def by_length(query, text): ...

@lasagna.reranker("keyword_overlap")   # explicit name
def keyword_overlap(query, text): ...

lasagna.reranker("by_length_2", by_length)   # a call, not a decorator

Each accepts paper=, claims= and version= keywords, which a run records as the component's provenance. The function each stage expects is listed in write a component.

register

register(
    stage: str,
    obj: Any,
    name: Optional[str] = None,
    *,
    paper: Optional[str] = None,
    claims: Optional[dict] = None,
    version: Optional[str] = None,
) -> Any

Register a function or class as a stage component; returns obj.

Built-in names are refused: a function registered as cross_encoder would replace the control arm of every sweep in the process, under the built-in's name and provenance. Re-registering one of your own names replaces it, so a notebook cell can be run again.

The registry holds every component, built in or yours. from lasagna.core.registry import registry gives you the shared instance (also lasagna.registry).

ComponentRegistry

ComponentRegistry()

Unified registry for RAG pipeline components.

Thread-safe singleton that stores component implementations by type and name. Supports both decorator-based and imperative registration for a clean researcher workflow.

Category aliasing: "enhancer" and "query_enhancer" refer to the same slot so that both the core and retrieval APIs work transparently.

list_components

list_components(
    component_type: Optional[str] = None,
) -> List[Dict[str, Any]]

Every listed component of one stage or all, with what it declares.

Each entry is what the stage's list_* helper returns, plus stage and builtin. Stages are in name order. Imports no component, so it is safe for a CLI listing.

provenance

provenance(
    component_type: str, name: str
) -> Dict[str, Any]

{"paper", "claims", "version"} a component declared, the ones it set.

Empty for an unknown name or a component that declared none. Resolves nothing.

is_builtin

is_builtin(component_type: str, name: str) -> bool

Whether the package itself registered this name (not a plugin or user).

has

has(component_type: str, name: str) -> bool

Check if a component is registered.

Raises:

Type Description
ValueError

If component_type is not a valid type.

get_class

get_class(component_type: str, name: str) -> Type

Get the component class (without instantiating).

Parameters:

Name Type Description Default
component_type str

Component category.

required
name str

Registered name.

required

Returns:

Type Description
Type

Component class.

Raises:

Type Description
KeyError

If component not found.

LangChain and LlamaIndex

from_langchain

from_langchain(
    obj: Any,
    name: Optional[str] = None,
    id_key: str = "doc_id",
) -> str

Parameters:

Name Type Description Default
obj Any

The object you built: a document compressor (a reranker), embeddings (an embedder) or a retriever (it brings its own index).

required
name Optional[str]

The registered name; langchain.<Class> by default.

None
id_key str

The metadata key holding a returned document's id.

'doc_id'

Returns:

Type Description
str

The registered name, for a sweep's rerankers, embedders or a

str

retriever: override.

from_llamaindex

from_llamaindex(
    obj: Any,
    name: Optional[str] = None,
    id_key: str = "doc_id",
) -> str

Parameters:

Name Type Description Default
obj Any

The object you built: a node postprocessor (a reranker), an embedding (an embedder) or a retriever (it brings its own index).

required
name Optional[str]

The registered name; llamaindex.<Class> by default.

None
id_key str

The metadata key holding a returned node's document id; the node's source document id is the fallback.

'doc_id'

Returns:

Type Description
str

The registered name, for a sweep's rerankers, embedders or a

str

retriever: override.

Evaluation

Experiment

Experiment(
    config: ExperimentConfig,
    eval_fn: Optional[Callable] = None,
)

from_file classmethod

from_file(
    path: str, eval_fn: Optional[Callable] = None
) -> "Experiment"

from_dict classmethod

from_dict(
    data: Dict[str, Any], eval_fn: Optional[Callable] = None
) -> "Experiment"

generate_tasks

generate_tasks() -> List[BenchmarkTask]

run async

run(
    progress_callback: Optional[
        Callable[[int, int, str], None]
    ] = None,
) -> BenchmarkResults

Parameters:

Name Type Description Default
progress_callback Optional[Callable[[int, int, str], None]]

Optional (completed, total, task_key) -> None.

None

Returns:

Type Description
BenchmarkResults

class:BenchmarkResults with all task outcomes.

ExperimentConfig dataclass

ExperimentConfig(
    name: str = "experiment",
    description: str = "",
    benchmarks: List[BenchmarkSpec] = list(),
    pipeline: PipelineSweepSpec = PipelineSweepSpec(),
    mode: str = "auto",
    n_runs: int = 1,
    variance_source: str = "run",
    n_samples: Optional[int] = None,
    seed: int = 42,
    max_concurrency: int = 4,
    checkpoint_dir: str = "",
    output_dir: str = "",
    output_formats: List[str] = (
        lambda: ["markdown", "json"]
    )(),
    judge_model: str = "",
    ingestion_per_config: bool = False,
    max_corpus_docs: int = 0,
    ingest_failure_tolerance: float = 0.0,
    tracks: List[str] = (
        lambda: ["retrieval", "generation"]
    )(),
    llm_cache: LLMCacheSettings = LLMCacheSettings(),
    prices: Optional[PriceTable] = None,
    base_dir: str = "",
    _resolved_output_dir: Optional[str] = None,
)

effective_output_dir

effective_output_dir() -> str

latest_output_dir

latest_output_dir() -> Optional[str]

Client and backend

KnowledgeClient

KnowledgeClient(
    config: Optional[KnowledgeConfig] = None,
    session_id: Optional[str] = None,
)

Attributes:

Name Type Description
config KnowledgeConfig

Current knowledge configuration

session_id str

Session identifier for multi-tenancy

documents DocumentManager

DocumentManager for document operations

citations CitationManager

CitationManager for citation tracking

Parameters:

Name Type Description Default
config Optional[KnowledgeConfig]

Knowledge configuration. Uses defaults if not provided.

None
session_id Optional[str]

Session identifier for multi-tenant usage. Auto-generated if not provided.

None

Raises:

Type Description
ValueError

If session_id is an invalid string like 'None'.

session_id property writable

session_id: str

config property

documents property

documents: DocumentManager

search property

search: SearchManager

citations property

citations: CitationManager

config_manager property

config_manager: ConfigManager

focused_document_ids property

focused_document_ids: Optional[List[str]]

from_url classmethod

from_url(
    url: str,
    api_key: Optional[str] = None,
    session_id: Optional[str] = None,
    session_token: Optional[str] = None,
) -> KnowledgeClient

Parameters:

Name Type Description Default
url str

Base URL of the Lasagna API (e.g. https://rag.myapp.com)

required
api_key Optional[str]

A key from the server's RAG_API_KEYS. With RAG_REQUIRE_AUTH on, the client mints a session token with it (POST /api/v1/sessions) when the server first answers 401, and its session becomes the token's. Also sent as Authorization: Bearer.

None
session_id Optional[str]

Session identifier. Auto-generated if not provided. With auth on, only an admin may name one, so leave it out.

None
session_token Optional[str]

A token from POST /api/v1/sessions, sent as X-Session-Token on every request.

None

Returns:

Type Description
KnowledgeClient

KnowledgeClient connected to the remote server

upload async

upload(
    file_path: Union[str, Path],
    filename: Optional[str] = None,
    metadata: Optional[Dict[str, Any]] = None,
    document_id: Optional[str] = None,
    allow_duplicates: bool = False,
) -> UploadResult

Parameters:

Name Type Description Default
file_path Union[str, Path]

Path to the document file (must exist)

required
filename Optional[str]

Optional display name (defaults to original filename)

None
metadata Optional[Dict[str, Any]]

Not stored; a non-empty one raises ValueError

None
document_id Optional[str]

Optional explicit document ID for benchmark evaluation

None
allow_duplicates bool

Index the file even when the session already holds the same content. By default that document is returned instead, with duplicate_of set.

False

Returns:

Type Description
UploadResult

UploadResult with document_id, chunk_count, status

Raises:

Type Description
FileNotFoundError

If file doesn't exist

ValueError

If file type not supported

search_documents async

search_documents(
    query: str,
    top_k: int = 5,
    min_score: Optional[float] = None,
    document_ids: Optional[List[str]] = None,
    routing_tier: Optional[str] = None,
) -> SearchResults

Parameters:

Name Type Description Default
query str

Natural language search query

required
top_k int

Maximum number of results

5
min_score Optional[float]

Drop results whose score is below this. A score is the reranker's when the profile reranks, else the retrieval score ((cosine similarity + 1) / 2 for dense search). Default: no threshold.

None
document_ids Optional[List[str]]

Optional filter by document IDs (overrides focus)

None
routing_tier Optional[str]

Force a routing tier ("fast", "standard", "comprehensive"). If None, the router auto-selects.

None

Returns:

Type Description
SearchResults

SearchResults containing ranked chunks with scores

get_context async

get_context(
    query: str,
    document_ids: Optional[List[str]] = None,
    max_chunks: int = 5,
    routing_tier: Optional[str] = None,
) -> str

Parameters:

Name Type Description Default
query str

Natural language search query

required
document_ids Optional[List[str]]

Optional filter by document IDs (overrides focus)

None
max_chunks int

Maximum chunks to include in context

5
routing_tier Optional[str]

Force a routing tier ("fast", "standard", "comprehensive"). If None, the router auto-selects.

None

Returns:

Type Description
str

Formatted context string with citations

list_documents async

list_documents(
    status: Optional[DocumentStatus] = None,
) -> List[Document]

Parameters:

Name Type Description Default
status Optional[DocumentStatus]

Optional filter by status

None

Returns:

Type Description
List[Document]

List of Document objects

delete_document async

delete_document(document_id: str) -> bool

Parameters:

Name Type Description Default
document_id str

ID of document to delete

required

Returns:

Type Description
bool

True if deleted, False if not found

set_focused_documents

set_focused_documents(document_ids: List[str]) -> None

Parameters:

Name Type Description Default
document_ids List[str]

List of document IDs to focus on

required

clear_focused_documents

clear_focused_documents() -> None
agentic_search(
    query: str,
    max_iterations: Optional[int] = None,
    document_ids: Optional[List[str]] = None,
) -> AgenticSearchResults

Parameters:

Name Type Description Default
query str

Initial search query

required
max_iterations Optional[int]

Maximum search iterations (default from config)

None
document_ids Optional[List[str]]

Optional filter by document IDs

None

Returns:

Type Description
AgenticSearchResults

AgenticSearchResults with hop data and final context

set_config async

set_config(
    *, reindex: bool = False, force: bool = False, **kwargs
) -> None

Parameters:

Name Type Description Default
**kwargs

Configuration options to update

{}

use_preset

use_preset(preset: str) -> None

Parameters:

Name Type Description Default
preset str

One of 'speed', 'standard', 'balanced', 'max_quality'

required

Raises:

Type Description
ValueError

If preset name not recognized

get_config_dict

get_config_dict() -> Dict[str, Any]

Returns:

Type Description
Dict[str, Any]

Dictionary with all configuration values

get_lifecycle_policy async

get_lifecycle_policy() -> Dict[str, Any]

Returns:

Type Description
Dict[str, Any]

Dict with all policy fields (soft_delete_grace_hours, gc_cycle_hours, …)

set_lifecycle_policy async

set_lifecycle_policy(**updates: Any) -> Dict[str, Any]

Parameters:

Name Type Description Default
**updates Any

Policy fields to change. Supported keys: soft_delete_grace_hours, document_ttl_days (None or 0 disables TTL), error_retention_days, session_idle_days, gc_cycle_hours, orphan_scan_hours, safety_threshold_percent, batch_size, reconcile_quota_on_startup.

{}

Returns:

Type Description
Dict[str, Any]

Dict with the full updated policy.

close async

close(processing_timeout: float = 600.0) -> None

delete_session async

delete_session(confirm: bool = False) -> Dict[str, Any]

Parameters:

Name Type Description Default
confirm bool

Must be True to proceed (safety check)

False

Returns:

Type Description
Dict[str, Any]

Dictionary with counts of deleted items:

Dict[str, Any]

{ "documents_deleted": int, "citations_deleted": int, "cache_invalidated": bool, "session_cleared": bool, "errors": list[str], # partial failure messages, if any

Dict[str, Any]

}

Raises:

Type Description
ValueError

If confirm is not True

KnowledgeError

If deletion operation fails

__aenter__ async

__aenter__() -> KnowledgeClient

__aexit__ async

__aexit__(exc_type, exc_val, exc_tb) -> None

__repr__

__repr__() -> str

KnowledgeConfig dataclass

KnowledgeConfig(
    db_path: Optional[str] = None,
    upload_dir: Optional[str] = None,
    enable_hybrid_search: bool = True,
    enable_reranking: bool = True,
    enable_mmr: bool = True,
    enable_hyde: bool = False,
    enable_ocr: bool = False,
    enable_query_expansion: bool = False,
    enable_query_decomposition: bool = False,
    enable_embedding_cache: bool = True,
    enable_search_cache: bool = True,
    vector_backend: VectorBackend = MILVUS,
    vector_backend_config: Optional[Dict[str, Any]] = None,
    embedding_provider: EmbeddingProvider = HUGGINGFACE,
    embedding_model: str = "BAAI/bge-m3",
    embedding_model_fallback: Optional[
        str
    ] = "BAAI/bge-large-en-v1.5",
    embedding_dim: int = 1024,
    embedding_truncate_dim: Optional[int] = None,
    normalize_embeddings: bool = True,
    use_gpu: bool = True,
    batch_size: int = 32,
    chunking_strategy: ChunkingStrategy = SEMANTIC,
    chunk_size: int = 800,
    chunk_overlap: int = 0,
    semantic_threshold: float = 0.75,
    min_chunk_size: int = 200,
    max_chunk_size: int = 1500,
    enable_hierarchical: bool = True,
    parent_chunk_size: int = 2000,
    child_chunk_size: int = 500,
    auto_merge_threshold: float = 0.5,
    preserve_tables: bool = True,
    preserve_headers: bool = True,
    max_content_length: int = 4000,
    default_top_k: int = 20,
    rerank_top_k: int = 5,
    similarity_threshold: float = 0.3,
    hybrid_alpha: float = 0.7,
    mmr_score_normalization: str = "sigmoid",
    rrf_k: int = 60,
    coverage_scorer_mode: str = "keyword",
    reranker_model: str = "mixedbread-ai/mxbai-rerank-large-v1",
    reranker_batch_size: int = 16,
    mmr_lambda: float = 0.5,
    enable_context_reordering: bool = True,
    enable_context_compression: bool = False,
    compression_method: str = "extractive",
    compression_ratio: float = 0.3,
    enable_graph_retrieval: bool = False,
    graph_max_hops: int = 2,
    graph_entity_types: Optional[List[str]] = None,
    graph_extraction_model: str = "",
    custom_reranker: str = "",
    llm_reranker_model: str = "",
    llm_reranker_window_size: int = 20,
    colbert_model: str = "colbert-ir/colbertv2.0",
    sparse_method: str = "bm25",
    enable_contextual_retrieval: bool = False,
    enable_rag_fusion: bool = False,
    rag_fusion_n_queries: int = 3,
    enable_crag: bool = False,
    crag_web_search_fallback: bool = False,
    docling_enabled: bool = True,
    docling_mode: str = "auto",
    docling_pdf_backend: str = "docling_parse",
    docling_ocr_enabled: bool = True,
    docling_table_structure: bool = True,
    docling_max_tokens: int = 512,
    docling_timeout: int = 300,
    embedding_backend: str = "auto",
    enable_query_routing: bool = True,
    routing_strategy: str = "rule_based",
    routing_default_tier: str = "standard",
    routing_confidence_threshold: float = 0.5,
    enable_query_classification: bool = True,
    hyde_model: str = "default",
    hyde_strategy: HyDEStrategy = ADAPTIVE,
    hyde_n_docs: int = 3,
    max_query_variations: int = 3,
    use_agentic_rag: bool = True,
    max_agent_iterations: int = 3,
    chunk_refinement_method: str = "auto",
    refinement_model: str = (
        lambda: _get_default_model()
    )(),
    agent_temperature: float = 0.1,
    use_structured_graph: bool = False,
    agentic_pipeline: Optional[str] = None,
    enable_hallucination_check: bool = False,
    enable_answer_quality_check: bool = False,
    chunk_retrieval_strategy: ChunkRetrievalStrategy = ADAPTIVE,
    chunk_retrieval_threshold: float = 0.5,
    chunk_retrieval_max: int = 20,
    chunk_retrieval_min: int = 2,
    score_gap_buffer: int = 2,
    min_gap_ratio: float = 0.15,
    enable_citations: bool = True,
    citation_format: CitationFormat = STABLE_ID,
    citation_id_length: int = 8,
    verify_citations: bool = True,
    track_citations_db: bool = True,
    show_page_numbers: bool = True,
    citation_db_max_age_hours: int = 168,
    citation_db_max_per_session: int = 1000,
    document_awareness_enabled: bool = True,
    enrichment_strategy: EnrichmentStrategy = FIRST_TOKENS,
    first_tokens_count: int = 150,
    max_documents_in_context: int = 10,
    ocr_engine: OCREngine = EASYOCR,
    ocr_languages: List[str] = (lambda: ["en"])(),
    ocr_confidence_threshold: float = 0.5,
    embedding_cache_size: int = 10000,
    search_cache_ttl: int = 300,
    search_cache_max_size: int = 1000,
    log_level: str = "INFO",
    enable_prometheus: bool = False,
    enable_tracing: bool = False,
    database_backend: str = "sqlite",
    database_dsn: Optional[str] = None,
    cache_backend: str = "memory",
    redis_url: Optional[str] = None,
    celery_enabled: bool = False,
    tenant_isolation: str = "none",
    quota_enabled: bool = False,
    rate_limiting_enabled: bool = False,
    connection_pool_size: int = 1,
    storage_backend: str = "local",
    storage_backend_config: Optional[Dict[str, Any]] = None,
    database_pool_min: int = 2,
    database_pool_max: int = 10,
    celery_broker_url: Optional[str] = None,
    celery_result_backend: Optional[str] = None,
    redis_pool_size: int = 10,
)

db_path class-attribute instance-attribute

db_path: Optional[str] = None

upload_dir class-attribute instance-attribute

upload_dir: Optional[str] = None
enable_hybrid_search: bool = True

enable_reranking class-attribute instance-attribute

enable_reranking: bool = True

enable_mmr class-attribute instance-attribute

enable_mmr: bool = True

enable_hyde class-attribute instance-attribute

enable_hyde: bool = False

enable_ocr class-attribute instance-attribute

enable_ocr: bool = False

enable_query_expansion class-attribute instance-attribute

enable_query_expansion: bool = False

enable_query_decomposition class-attribute instance-attribute

enable_query_decomposition: bool = False

enable_embedding_cache class-attribute instance-attribute

enable_embedding_cache: bool = True

enable_search_cache class-attribute instance-attribute

enable_search_cache: bool = True

vector_backend class-attribute instance-attribute

vector_backend: VectorBackend = VectorBackend.MILVUS

vector_backend_config class-attribute instance-attribute

vector_backend_config: Optional[Dict[str, Any]] = None

embedding_provider class-attribute instance-attribute

embedding_provider: EmbeddingProvider = (
    EmbeddingProvider.HUGGINGFACE
)

embedding_model class-attribute instance-attribute

embedding_model: str = 'BAAI/bge-m3'

embedding_model_fallback class-attribute instance-attribute

embedding_model_fallback: Optional[str] = (
    "BAAI/bge-large-en-v1.5"
)

embedding_dim class-attribute instance-attribute

embedding_dim: int = 1024

embedding_truncate_dim class-attribute instance-attribute

embedding_truncate_dim: Optional[int] = None

normalize_embeddings class-attribute instance-attribute

normalize_embeddings: bool = True

use_gpu class-attribute instance-attribute

use_gpu: bool = True

batch_size class-attribute instance-attribute

batch_size: int = 32

chunking_strategy class-attribute instance-attribute

chunking_strategy: ChunkingStrategy = (
    ChunkingStrategy.SEMANTIC
)

chunk_size class-attribute instance-attribute

chunk_size: int = 800

chunk_overlap class-attribute instance-attribute

chunk_overlap: int = 0

semantic_threshold class-attribute instance-attribute

semantic_threshold: float = 0.75

min_chunk_size class-attribute instance-attribute

min_chunk_size: int = 200

max_chunk_size class-attribute instance-attribute

max_chunk_size: int = 1500

enable_hierarchical class-attribute instance-attribute

enable_hierarchical: bool = True

parent_chunk_size class-attribute instance-attribute

parent_chunk_size: int = 2000

child_chunk_size class-attribute instance-attribute

child_chunk_size: int = 500

auto_merge_threshold class-attribute instance-attribute

auto_merge_threshold: float = 0.5

preserve_tables class-attribute instance-attribute

preserve_tables: bool = True

preserve_headers class-attribute instance-attribute

preserve_headers: bool = True

max_content_length class-attribute instance-attribute

max_content_length: int = 4000

default_top_k class-attribute instance-attribute

default_top_k: int = 20

rerank_top_k class-attribute instance-attribute

rerank_top_k: int = 5

similarity_threshold class-attribute instance-attribute

similarity_threshold: float = 0.3

hybrid_alpha class-attribute instance-attribute

hybrid_alpha: float = 0.7

mmr_score_normalization class-attribute instance-attribute

mmr_score_normalization: str = 'sigmoid'

rrf_k class-attribute instance-attribute

rrf_k: int = 60

coverage_scorer_mode class-attribute instance-attribute

coverage_scorer_mode: str = 'keyword'

reranker_model class-attribute instance-attribute

reranker_model: str = 'mixedbread-ai/mxbai-rerank-large-v1'

reranker_batch_size class-attribute instance-attribute

reranker_batch_size: int = 16

mmr_lambda class-attribute instance-attribute

mmr_lambda: float = 0.5

enable_context_reordering class-attribute instance-attribute

enable_context_reordering: bool = True

enable_context_compression class-attribute instance-attribute

enable_context_compression: bool = False

compression_method class-attribute instance-attribute

compression_method: str = 'extractive'

compression_ratio class-attribute instance-attribute

compression_ratio: float = 0.3

enable_graph_retrieval class-attribute instance-attribute

enable_graph_retrieval: bool = False

graph_max_hops class-attribute instance-attribute

graph_max_hops: int = 2

graph_entity_types class-attribute instance-attribute

graph_entity_types: Optional[List[str]] = None

graph_extraction_model class-attribute instance-attribute

graph_extraction_model: str = ''

custom_reranker class-attribute instance-attribute

custom_reranker: str = ''

llm_reranker_model class-attribute instance-attribute

llm_reranker_model: str = ''

llm_reranker_window_size class-attribute instance-attribute

llm_reranker_window_size: int = 20

colbert_model class-attribute instance-attribute

colbert_model: str = 'colbert-ir/colbertv2.0'

sparse_method class-attribute instance-attribute

sparse_method: str = 'bm25'

enable_contextual_retrieval class-attribute instance-attribute

enable_contextual_retrieval: bool = False

enable_rag_fusion class-attribute instance-attribute

enable_rag_fusion: bool = False

rag_fusion_n_queries class-attribute instance-attribute

rag_fusion_n_queries: int = 3

enable_crag class-attribute instance-attribute

enable_crag: bool = False

crag_web_search_fallback class-attribute instance-attribute

crag_web_search_fallback: bool = False

docling_enabled class-attribute instance-attribute

docling_enabled: bool = True

docling_mode class-attribute instance-attribute

docling_mode: str = 'auto'

docling_pdf_backend class-attribute instance-attribute

docling_pdf_backend: str = 'docling_parse'

docling_ocr_enabled class-attribute instance-attribute

docling_ocr_enabled: bool = True

docling_table_structure class-attribute instance-attribute

docling_table_structure: bool = True

docling_max_tokens class-attribute instance-attribute

docling_max_tokens: int = 512

docling_timeout class-attribute instance-attribute

docling_timeout: int = 300

embedding_backend class-attribute instance-attribute

embedding_backend: str = 'auto'

enable_query_routing class-attribute instance-attribute

enable_query_routing: bool = True

routing_strategy class-attribute instance-attribute

routing_strategy: str = 'rule_based'

routing_default_tier class-attribute instance-attribute

routing_default_tier: str = 'standard'

routing_confidence_threshold class-attribute instance-attribute

routing_confidence_threshold: float = 0.5

enable_query_classification class-attribute instance-attribute

enable_query_classification: bool = True

hyde_model class-attribute instance-attribute

hyde_model: str = 'default'

hyde_strategy class-attribute instance-attribute

hyde_strategy: HyDEStrategy = HyDEStrategy.ADAPTIVE

hyde_n_docs class-attribute instance-attribute

hyde_n_docs: int = 3

max_query_variations class-attribute instance-attribute

max_query_variations: int = 3

use_agentic_rag class-attribute instance-attribute

use_agentic_rag: bool = True

max_agent_iterations class-attribute instance-attribute

max_agent_iterations: int = 3

chunk_refinement_method class-attribute instance-attribute

chunk_refinement_method: str = 'auto'

refinement_model class-attribute instance-attribute

refinement_model: str = field(
    default_factory=lambda: _get_default_model()
)

agent_temperature class-attribute instance-attribute

agent_temperature: float = 0.1

use_structured_graph class-attribute instance-attribute

use_structured_graph: bool = False

agentic_pipeline class-attribute instance-attribute

agentic_pipeline: Optional[str] = None

enable_hallucination_check class-attribute instance-attribute

enable_hallucination_check: bool = False

enable_answer_quality_check class-attribute instance-attribute

enable_answer_quality_check: bool = False

chunk_retrieval_strategy class-attribute instance-attribute

chunk_retrieval_strategy: ChunkRetrievalStrategy = (
    ChunkRetrievalStrategy.ADAPTIVE
)

chunk_retrieval_threshold class-attribute instance-attribute

chunk_retrieval_threshold: float = 0.5

chunk_retrieval_max class-attribute instance-attribute

chunk_retrieval_max: int = 20

chunk_retrieval_min class-attribute instance-attribute

chunk_retrieval_min: int = 2

score_gap_buffer class-attribute instance-attribute

score_gap_buffer: int = 2

min_gap_ratio class-attribute instance-attribute

min_gap_ratio: float = 0.15

enable_citations class-attribute instance-attribute

enable_citations: bool = True

citation_format class-attribute instance-attribute

citation_format: CitationFormat = CitationFormat.STABLE_ID

citation_id_length class-attribute instance-attribute

citation_id_length: int = 8

verify_citations class-attribute instance-attribute

verify_citations: bool = True

track_citations_db class-attribute instance-attribute

track_citations_db: bool = True

show_page_numbers class-attribute instance-attribute

show_page_numbers: bool = True

citation_db_max_age_hours class-attribute instance-attribute

citation_db_max_age_hours: int = 168

citation_db_max_per_session class-attribute instance-attribute

citation_db_max_per_session: int = 1000

document_awareness_enabled class-attribute instance-attribute

document_awareness_enabled: bool = True

enrichment_strategy class-attribute instance-attribute

enrichment_strategy: EnrichmentStrategy = (
    EnrichmentStrategy.FIRST_TOKENS
)

first_tokens_count class-attribute instance-attribute

first_tokens_count: int = 150

max_documents_in_context class-attribute instance-attribute

max_documents_in_context: int = 10

ocr_engine class-attribute instance-attribute

ocr_engine: OCREngine = OCREngine.EASYOCR

ocr_languages class-attribute instance-attribute

ocr_languages: List[str] = field(
    default_factory=lambda: ["en"]
)

ocr_confidence_threshold class-attribute instance-attribute

ocr_confidence_threshold: float = 0.5

embedding_cache_size class-attribute instance-attribute

embedding_cache_size: int = 10000

search_cache_ttl class-attribute instance-attribute

search_cache_ttl: int = 300

search_cache_max_size class-attribute instance-attribute

search_cache_max_size: int = 1000

log_level class-attribute instance-attribute

log_level: str = 'INFO'

enable_prometheus class-attribute instance-attribute

enable_prometheus: bool = False

enable_tracing class-attribute instance-attribute

enable_tracing: bool = False

database_backend class-attribute instance-attribute

database_backend: str = 'sqlite'

database_dsn class-attribute instance-attribute

database_dsn: Optional[str] = None

cache_backend class-attribute instance-attribute

cache_backend: str = 'memory'

redis_url class-attribute instance-attribute

redis_url: Optional[str] = None

celery_enabled class-attribute instance-attribute

celery_enabled: bool = False

tenant_isolation class-attribute instance-attribute

tenant_isolation: str = 'none'

quota_enabled class-attribute instance-attribute

quota_enabled: bool = False

rate_limiting_enabled class-attribute instance-attribute

rate_limiting_enabled: bool = False

connection_pool_size class-attribute instance-attribute

connection_pool_size: int = 1

storage_backend class-attribute instance-attribute

storage_backend: str = 'local'

storage_backend_config class-attribute instance-attribute

storage_backend_config: Optional[Dict[str, Any]] = None

database_pool_min class-attribute instance-attribute

database_pool_min: int = 2

database_pool_max class-attribute instance-attribute

database_pool_max: int = 10

celery_broker_url class-attribute instance-attribute

celery_broker_url: Optional[str] = None

celery_result_backend class-attribute instance-attribute

celery_result_backend: Optional[str] = None

redis_pool_size class-attribute instance-attribute

redis_pool_size: int = 10

explicit_fields property

explicit_fields: frozenset

__post_init__

__post_init__()

to_dict

to_dict() -> Dict[str, Any]

Returns:

Type Description
Dict[str, Any]

Dictionary representation of config

with_updates

with_updates(**kwargs) -> KnowledgeConfig

Parameters:

Name Type Description Default
**kwargs

Configuration options to update

{}

Returns:

Type Description
KnowledgeConfig

New KnowledgeConfig with updates applied

from_dict classmethod

from_dict(data: Dict[str, Any]) -> KnowledgeConfig

Parameters:

Name Type Description Default
data Dict[str, Any]

Dictionary with configuration values

required

Returns:

Type Description
KnowledgeConfig

KnowledgeConfig instance

RAGBackend

RAGBackend()

__new__

__new__()

get_collection_embedding_dim

get_collection_embedding_dim(
    collection_name: str, backend: VectorStoreAdapter = None
) -> Optional[int]

embedder_for

embedder_for(config: RAGConfig) -> EmbeddingManager

reload_embedding_manager

reload_embedding_manager(config: RAGConfig) -> None

force_rebuild_collection

force_rebuild_collection(confirm: bool = False) -> bool

ensure_collection_for_config

ensure_collection_for_config(config: RAGConfig) -> None

recreate_collection_for_config

recreate_collection_for_config(
    config: RAGConfig, backend: VectorStoreAdapter = None
) -> None

upload_document

upload_document(
    file_path: str,
    session_id: str,
    filename: Optional[str] = None,
    document_id: Optional[str] = None,
    _chunker_override: Any = None,
    _document_processor_override: Any = None,
    refuse_when_busy: bool = False,
    wait_when_busy: float = 0.0,
    allow_duplicates: bool = False,
) -> Document

process_document

process_document(
    document: Document,
    file_path: str,
    config: Optional[RAGConfig] = None,
)

get_session_config

get_session_config(
    session_id: Optional[str] = None,
) -> RAGConfig

Parameters:

Name Type Description Default
session_id Optional[str]

Optional session identifier

None

Returns:

Type Description
RAGConfig

RAGConfig instance (session-aware if session_id provided)

get_vector_backend

get_vector_backend(
    session_id: Optional[str] = None,
) -> VectorStoreAdapter

search

search(
    query: str,
    session_id: str,
    top_k: Optional[int] = None,
    min_score: Optional[float] = -100.0,
    document_ids: Optional[List[str]] = None,
    use_hyde: bool = True,
    use_reranking: bool = True,
    trace_id: Optional[str] = None,
    routing_tier: Optional[str] = None,
    _from_routing: bool = False,
    _reranker_override: Optional[Any] = None,
    _enhancer_override: Optional[Any] = None,
    _embedder_override: Optional[Any] = None,
    query_config_overrides: Optional[Any] = None,
    _retriever_override: Optional[Any] = None,
    _agentic_pipeline_override: Optional[Any] = None,
    _graph_node_overrides: Optional[Dict[str, Any]] = None,
) -> List[SearchResult]

search_with_citations

search_with_citations(
    query: str,
    session_id: str,
    top_k: Optional[int] = None,
    document_ids: Optional[List[str]] = None,
    trace_id: Optional[str] = None,
    routing_tier: Optional[str] = None,
    _reranker_override: Optional[Any] = None,
    _enhancer_override: Optional[Any] = None,
    min_score: Optional[float] = None,
) -> Tuple[List[SearchResult], List[Citation], str]
async_search(
    query: str,
    session_id: str,
    top_k: Optional[int] = None,
    min_score: Optional[float] = -100.0,
    document_ids: Optional[List[str]] = None,
    use_hyde: bool = True,
    use_reranking: bool = True,
    trace_id: Optional[str] = None,
    routing_tier: Optional[str] = None,
    _reranker_override: Optional[Any] = None,
    _enhancer_override: Optional[Any] = None,
) -> List[SearchResult]

async_search_with_citations async

async_search_with_citations(
    query: str,
    session_id: str,
    top_k: Optional[int] = None,
    document_ids: Optional[List[str]] = None,
    trace_id: Optional[str] = None,
    routing_tier: Optional[str] = None,
    _reranker_override: Optional[Any] = None,
    _enhancer_override: Optional[Any] = None,
    min_score: Optional[float] = None,
) -> Tuple[List[SearchResult], List[Citation], str]

search_multi_query

search_multi_query(
    query: str,
    session_id: str,
    top_k: Optional[int] = None,
    document_ids: Optional[List[str]] = None,
    n_variations: int = 3,
    trace_id: Optional[str] = None,
    _reranker_override: Optional[Any] = None,
    _enhancer_override: Optional[Any] = None,
) -> List[SearchResult]
async_agentic_search(
    query: str,
    session_id: str,
    top_k: Optional[int] = None,
    document_ids: Optional[List[str]] = None,
    trace_id: Optional[str] = None,
    routing_decision: Any = None,
)

Parameters:

Name Type Description Default
routing_decision Any

Pre-computed RoutingDecision from upstream. Forwarded to AgenticRAG.retrieve() so the structured graph can skip re-classification.

None

Returns:

Type Description

AgenticRAGResult with formatted_context, citations, chunks, metrics.

get_documents

get_documents(session_id: str) -> List[DocumentMetadata]

get_document_by_id

get_document_by_id(
    document_id: str, session_id: str
) -> Optional[DocumentMetadata]

delete_document

delete_document(
    document_id: str,
    session_id: str,
    *,
    keep_file: bool = False,
) -> bool

reindex_document

reindex_document(
    document_id: str,
    session_id: str,
    *,
    config: Optional[Any] = None,
) -> Document

clear_session_state

clear_session_state(session_id: str) -> Dict[str, Any]

Parameters:

Name Type Description Default
session_id str

Session ID to clear

required

Returns:

Type Description
Dict[str, Any]

Dict with cleanup results:

Dict[str, Any]

{ "cache_invalidated": bool, "bm25_cleared": bool, "session_cleared": bool,

Dict[str, Any]

}

get_context

get_context(
    search_results: List[SearchResult], max_chunks: int = 5
) -> str

get_document_chunks

get_document_chunks(
    document_id: str,
    session_id: str,
    limit: int = 100,
    offset: int = 0,
) -> List[Dict[str, Any]]

get_document_file_path

get_document_file_path(
    document_id: str, session_id: str
) -> Optional[str]

soft_delete_document

soft_delete_document(
    document_id: str, session_id: str
) -> dict

Parameters:

Name Type Description Default
document_id str

Document to archive.

required
session_id str

Session the document belongs to (authorization).

required

Returns:

Type Description
dict

Updated document metadata dict.

Raises:

Type Description
ValueError

If the document does not exist or belongs to a different session.

restore_document

restore_document(document_id: str, session_id: str) -> dict

Parameters:

Name Type Description Default
document_id str

Soft-deleted document to restore.

required
session_id str

Session the document belongs to (authorization).

required

Returns:

Type Description
dict

Updated document metadata dict (status=READY).

Raises:

Type Description
ValueError

If the document is not soft-deleted.

DocumentExpiredError

If the grace window has already expired.

bulk_delete_session

bulk_delete_session(
    session_id: str, *, confirm: bool = False
) -> BulkDeleteResult

Parameters:

Name Type Description Default
session_id str

Session whose documents should be purged.

required
confirm bool

Must be True — acts as a safety guard against accidental calls.

False

Returns:

Type Description
BulkDeleteResult

BulkDeleteResult with counts and bytes freed.

bulk_delete_documents

bulk_delete_documents(
    document_ids: List[str], session_id: str
) -> BulkDeleteResult

Parameters:

Name Type Description Default
document_ids List[str]

IDs of documents to delete.

required
session_id str

Session authorization — documents not in this session are skipped.

required

Returns:

Type Description
BulkDeleteResult

BulkDeleteResult with counts.

run_gc

run_gc(*, session_id: Optional[str] = None) -> GCReport

Parameters:

Name Type Description Default
session_id Optional[str]

Optional — limit GC to a single session.

None

Returns:

Type Description
GCReport

GCReport with per-phase results.

detect_orphans

detect_orphans(
    session_id: Optional[str] = None,
) -> ConsistencyReport

Parameters:

Name Type Description Default
session_id Optional[str]

Optional — limit scan to a single session.

None

Returns:

Type Description
ConsistencyReport

ConsistencyReport with db_only and vec_only orphan lists.

repair_orphans

repair_orphans(
    report: ConsistencyReport, *, dry_run: bool = True
) -> RepairReport

Parameters:

Name Type Description Default
report ConsistencyReport

Output from detect_orphans().

required
dry_run bool

If True (default), no changes are made — useful for previewing.

True

Returns:

Type Description
RepairReport

RepairReport describing what was (or would be) repaired.

get_gc_audit_log

get_gc_audit_log(limit: int = 20) -> List[Dict[str, Any]]

Parameters:

Name Type Description Default
limit int

Maximum number of entries to return (most recent first).

20

Returns:

Type Description
List[Dict[str, Any]]

List of dicts, one per GC phase run, with keys:

List[Dict[str, Any]]

run_id, phase, started_at, completed_at,

List[Dict[str, Any]]

docs_scanned, docs_cleaned, bytes_freed, errors.

get_stats

get_stats() -> Dict[str, Any]

get_rag_backend

get_rag_backend() -> RAGBackend

Returns:

Type Description
RAGBackend

The RAGBackend singleton instance

create_rag_backend

create_rag_backend(
    db_dir: Optional[Path] = None,
    upload_dir: Optional[Path] = None,
    llm_provider: str = "openai",
    rag_settings: Optional[Dict[str, Any]] = None,
) -> RAGBackend

Parameters:

Name Type Description Default
db_dir Optional[Path]

Directory for databases (Milvus, SQLite). Defaults to ./rag_data/dbs

None
upload_dir Optional[Path]

Directory for uploaded files. Defaults to ./rag_data/uploads

None
llm_provider str

LLM provider name ("openai", "anthropic", "azure", "google")

'openai'
rag_settings Optional[Dict[str, Any]]

Optional RAG configuration overrides (chunk_size, etc.)

None

Returns:

Type Description
RAGBackend

Configured RAGBackend instance

Vector backends

VectorStoreAdapter

Bases: ABC

capabilities abstractmethod property

capabilities: BackendCapabilities

backend_name abstractmethod property

backend_name: str

connect abstractmethod

connect() -> None

Raises:

Type Description
ConnectionError

If connection fails

disconnect abstractmethod

disconnect() -> None

is_connected abstractmethod

is_connected() -> bool

has_collection abstractmethod

has_collection(collection_name: str) -> bool

Parameters:

Name Type Description Default
collection_name str

Name of the collection

required

Returns:

Type Description
bool

True if collection exists

create_collection abstractmethod

create_collection(
    collection_name: str,
    schema: CollectionSchema,
    index_config: Optional[IndexConfig] = None,
) -> None

Parameters:

Name Type Description Default
collection_name str

Name for the new collection

required
schema CollectionSchema

Schema defining the collection fields

required
index_config Optional[IndexConfig]

Optional index configuration

None

Raises:

Type Description
ValueError

If collection already exists

drop_collection abstractmethod

drop_collection(collection_name: str) -> None

Parameters:

Name Type Description Default
collection_name str

Name of collection to delete

required

describe_collection abstractmethod

describe_collection(collection_name: str) -> CollectionInfo

Parameters:

Name Type Description Default
collection_name str

Name of the collection

required

Returns:

Type Description
CollectionInfo

CollectionInfo with schema and stats

describe_fields

describe_fields(
    collection_name: str,
) -> List[Dict[str, Any]]

get_collection_stats abstractmethod

get_collection_stats(
    collection_name: str,
) -> Dict[str, Any]

Parameters:

Name Type Description Default
collection_name str

Name of the collection

required

Returns:

Type Description
Dict[str, Any]

Dict with 'row_count' and other stats

create_index abstractmethod

create_index(
    collection_name: str,
    field_name: str,
    index_config: IndexConfig,
) -> None

Parameters:

Name Type Description Default
collection_name str

Name of the collection

required
field_name str

Name of the vector field to index

required
index_config IndexConfig

Index configuration

required

list_indexes abstractmethod

list_indexes(collection_name: str) -> List[str]

Parameters:

Name Type Description Default
collection_name str

Name of the collection

required

Returns:

Type Description
List[str]

List of field names that have indexes

has_index

has_index(collection_name: str, field_name: str) -> bool

insert abstractmethod

insert(
    collection_name: str,
    data: Union[Dict[str, Any], List[Dict[str, Any]]],
    partition_key: Optional[str] = None,
) -> List[Union[int, str]]

Parameters:

Name Type Description Default
collection_name str

Name of the collection

required
data Union[Dict[str, Any], List[Dict[str, Any]]]

Single document or list of documents

required
partition_key Optional[str]

Optional partition/namespace for tenant isolation. Backends with supports_partitions use this natively. Others ignore it (tenant filtering via metadata).

None

Returns:

Type Description
List[Union[int, str]]

List of inserted IDs

delete abstractmethod

delete(
    collection_name: str,
    filter_expr: FilterExpression,
    partition_key: Optional[str] = None,
) -> int

Parameters:

Name Type Description Default
collection_name str

Name of the collection

required
filter_expr FilterExpression

Backend-agnostic filter expression

required
partition_key Optional[str]

Optional partition/namespace for tenant isolation.

None

Returns:

Type Description
int

Number of deleted documents

Raises:

Type Description
ValueError

If filter_expr is empty or would match no conditions.

query abstractmethod

query(
    collection_name: str,
    filter_expr: Optional[FilterExpression] = None,
    output_fields: Optional[List[str]] = None,
    limit: int = 100,
    offset: int = 0,
    partition_key: Optional[str] = None,
) -> List[Dict[str, Any]]

Parameters:

Name Type Description Default
collection_name str

Name of the collection

required
filter_expr Optional[FilterExpression]

Optional filter expression

None
output_fields Optional[List[str]]

Fields to return (None = all)

None
limit int

Maximum results

100
offset int

Number of results to skip

0
partition_key Optional[str]

Optional partition/namespace for tenant isolation.

None

Returns:

Type Description
List[Dict[str, Any]]

List of matching documents

iter_all

iter_all(
    collection_name: str,
    filter_expr: Optional[FilterExpression] = None,
    output_fields: Optional[List[str]] = None,
    *,
    partition_key: Optional[str] = None,
    page_size: int = 1000,
) -> Iterator[Dict[str, Any]]

Yields:

Type Description
Dict[str, Any]

Every matching row, in backend order.

list_document_ids

list_document_ids(
    collection_name: str,
    session_id: Optional[str] = None,
    *,
    limit: int = 10000,
    offset: int = 0,
) -> List[str]

Parameters:

Name Type Description Default
collection_name str

Name of the collection to scan

required
session_id Optional[str]

Optional session filter to scope the scan

None
limit int

Maximum number of document IDs to return

10000
offset int

Number of results to skip (for pagination)

0

Returns:

Type Description
List[str]

List of distinct document_id strings.

session_filter

session_filter(
    collection_name: str, session_id: str
) -> FilterExpression

search abstractmethod

search(
    collection_name: str,
    query_embedding: List[float],
    vector_field: str = "embedding",
    filter_expr: Optional[FilterExpression] = None,
    limit: int = 10,
    output_fields: Optional[List[str]] = None,
    search_params: Optional[SearchParams] = None,
    partition_key: Optional[str] = None,
) -> List[VectorSearchResult]

Parameters:

Name Type Description Default
collection_name str

Name of the collection

required
query_embedding List[float]

Query vector

required
vector_field str

Name of the vector field to search

'embedding'
filter_expr Optional[FilterExpression]

Optional filter to narrow results

None
limit int

Maximum number of results

10
output_fields Optional[List[str]]

Fields to include in results

None
search_params Optional[SearchParams]

Search parameters (metric, ef, etc.)

None
partition_key Optional[str]

Optional partition/namespace for tenant isolation. When provided and the backend supports partitions, the search is scoped to only that partition's data.

None

Returns:

Type Description
List[VectorSearchResult]

List of VectorSearchResult sorted by similarity

hybrid_search(
    collection_name: str,
    query_text: str,
    query_embedding: List[float],
    vector_field: str = "embedding",
    sparse_field: str = "sparse_embedding",
    filter_expr: Optional[FilterExpression] = None,
    limit: int = 10,
    alpha: float = 0.7,
    output_fields: Optional[List[str]] = None,
    partition_key: Optional[str] = None,
    **kwargs: Any,
) -> List[VectorSearchResult]

Parameters:

Name Type Description Default
collection_name str

Name of the collection

required
query_text str

Raw query text (for BM25/sparse)

required
query_embedding List[float]

Dense query vector

required
vector_field str

Dense vector field name

'embedding'
sparse_field str

Sparse vector field name

'sparse_embedding'
filter_expr Optional[FilterExpression]

Optional filter

None
limit int

Maximum results

10
alpha float

Weight for dense (1.0 = pure dense)

0.7
output_fields Optional[List[str]]

Fields to include

None
partition_key Optional[str]

Optional partition/namespace for tenant isolation.

None
**kwargs Any

Backend-specific options (e.g., query_tokens, group_by_document).

{}

Returns:

Type Description
List[VectorSearchResult]

List of VectorSearchResult with combined scores

async_search(
    collection_name: str,
    query_embedding: List[float],
    vector_field: str = "embedding",
    filter_expr: Optional[FilterExpression] = None,
    limit: int = 10,
    output_fields: Optional[List[str]] = None,
    search_params: Optional[SearchParams] = None,
    partition_key: Optional[str] = None,
) -> List[VectorSearchResult]

async_insert async

async_insert(
    collection_name: str,
    data: List[Dict[str, Any]],
    partition_key: Optional[str] = None,
) -> None

has_partition

has_partition(
    collection_name: str, partition_name: str
) -> bool

create_partition

create_partition(
    collection_name: str, partition_name: str
) -> None

drop_partition

drop_partition(
    collection_name: str, partition_name: str
) -> None

list_partitions

list_partitions(collection_name: str) -> List[str]

prepare_index_params

prepare_index_params() -> Any

normalize_score

normalize_score(
    raw_score: float,
    metric_type: MetricType = COSINE,
    is_distance: bool = False,
) -> float

Parameters:

Name Type Description Default
raw_score float

The raw score from the backend

required
metric_type MetricType

The metric used for scoring

COSINE
is_distance bool

True if raw_score is distance (lower=better), False if similarity (higher=better)

False

Returns:

Type Description
float

Similarity score (typically [0, 1], may exceed 1.0 for IP)

supports_feature

supports_feature(feature: str) -> bool

Parameters:

Name Type Description Default
feature str

Feature name (e.g., 'hybrid_search', 'json_filters')

required

Returns:

Type Description
bool

True if feature is supported

get_effective_batch_size

get_effective_batch_size(requested: int) -> int

Parameters:

Name Type Description Default
requested int

Requested batch size

required

Returns:

Type Description
int

Effective batch size (min of requested and max supported)

flush

flush(collection_name: str) -> None

compact

compact(collection_name: str) -> None

register_backend

register_backend(
    name: str,
    backend_class: Type[VectorStoreAdapter],
    override: bool = False,
) -> None

Parameters:

Name Type Description Default
name str

Unique name for the backend

required
backend_class Type[VectorStoreAdapter]

Class implementing VectorStoreAdapter

required
override bool

If True, replace existing registration

False