zerda.context — Advanced Context Intelligence Engine

On this page

A retrieval-orchestration and context-engineering library for Retrieval-Augmented Generation (RAG) systems, with first-class support for mixed Arabic/English content.

What is this?

zerda.context is a Python package (module path: context, distributed as part of the zerda namespace per its own docstrings) that sits between your retrieval layer and your LLM. It takes a raw user query and a corpus of indexed chunks, and produces a clean, budgeted, validated context string ready to be injected into an LLM prompt.

It is not a vector database, an embedding model, or an LLM wrapper. It assumes you already have (or can provide) chunks of text and, optionally, an embedding function or vector store. Its job is everything around retrieval:

  • Understanding the query (intent, complexity, language, keywords, entities)
  • Fusing multiple retrieval signals (vector similarity, BM25 keyword search, metadata filters)
  • Filtering noise and duplicates
  • Ranking chunks by a composite, configurable score
  • Composing a final context string under a length/token budget
  • Validating that the resulting context is non-empty, well-sourced, and (optionally) relevant
  • Learning from usage over time to tune the context budget
  • Caching repeated queries
  • Supporting multi-turn conversations

That said, context is designed to plug directly into the rest of zerda when you want it to: ContextEngine.index()/index_documents() can index straight into a native zerda.vector_database backend (ChromaVectorDatabase, FAISSVectorDatabase, PineconeVectorDatabase), and index_documents() will chunk raw text for you using any zerda.chunks chunker — no external adapter needed. See ContextEngine.index_documents and the native integration recipe.

Architecture at a glance

This is the exact pipeline implemented in ContextEngine.run(). See Architecture for the full breakdown, including caching and multi-turn enrichment, which sit alongside this main flow.

Is this documentation complete?

This documentation was generated from a static read of the actual source code (10 modules, ~3,140 lines, in the context/ package — updated for the native zerda.chunks/zerda.vector_database integration added to models, retriever, and engine). Every class, function, configuration field, and exception described here was verified against the implementation. Where the source code does not provide enough information to answer a question with confidence (e.g., packaging metadata, version history, license, CI setup — none of these exist in the provided source tree), this documentation says so explicitly rather than guessing.

Where to go next

If you want to...Go to
Get running in 5 minutesQuickstart
Understand the pipeline stagesArchitecture
Understand core concepts (chunks, budgets, intents)Concepts
Tune behavior via configConfiguration
Browse the full APIAPI Overview
See real integration patternsCookbook
Read about Arabic-language supportConcepts → Language Handling

Module map

ModuleResponsibility
configAll configuration dataclasses
modelsCore data models (enums, QueryAnalysis, ScoredChunk, ContextResult, conversation history)
strategyAbstract base classes defining every extension point
query_analyzerRule-based query understanding (intent, complexity, keywords, language)
retrieverBM25, vector (native zerda.vector_database / external adapter / in-memory), metadata retrievers, and the hybrid RRF fusion orchestrator
pipelineChunk filtering, composite ranking, and context composition/templating
guard_and_learningContext validation, adaptive budget learning, budget allocation strategies, LRU cache
engineContextEngine — the main orchestrator — and the legacy ContextManager
legacy_compatBackward-compatible shims for an older, tuple-based API
__init__Public package exports