Python API Reference¶
The core entry points are documented via mkdocstrings. Key modules:
bijux_rag.rag.app ¶
Application services for the 'real RAG' path.
This module wires
clean -> chunk -> index -> retrieve -> (optional rerank) -> generate.
Both CLI and FastAPI boundary call into this layer to avoid drift.
RagApp dataclass ¶
RagApp(
generator=ExtractiveGenerator(),
reranker=LexicalOverlapReranker(),
profile="default",
)
RagBuildConfig dataclass ¶
RagBuildConfig(
chunk_env,
backend="bm25",
embedder="hash16",
sbert_model="all-MiniLM-L6-v2",
bm25_buckets=2048,
)
RAG build configuration.
RagIndex dataclass ¶
RagIndex(backend, index, fingerprint, schema_version=1)
In-memory index wrapper for deterministic CI profile.
ask ¶
ask(
*,
index_path,
query,
top_k=5,
filters=None,
embedder=None,
rerank=True,
)
Retrieve and answer with citations.
Source code in src/bijux_rag/rag/app.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
build_index_from_csv ¶
build_index_from_csv(*, csv_path, out_path, cfg)
Build and persist an index.
Returns:
| Type | Description |
|---|---|
str | The index fingerprint. |
Source code in src/bijux_rag/rag/app.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
ingest_csv_to_chunks ¶
ingest_csv_to_chunks(*, csv_path, env)
Ingest a CSV and return chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_path | Path | CSV path with columns: doc_id,title,abstract,categories. | required |
env | RagEnv | Chunking configuration. | required |
Returns:
| Type | Description |
|---|---|
list[Chunk] | A list of chunks (without embeddings for lexical backends). |
Source code in src/bijux_rag/rag/app.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
ingest_docs_to_chunks ¶
ingest_docs_to_chunks(*, docs, env)
Ingest in-memory docs and return chunks.
Source code in src/bijux_rag/rag/app.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
parse_filters ¶
parse_filters(filters)
Parse CLI/API filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters | list[str] | None | list like ["category=cs.AI", "doc_id=foo"]. | required |
Source code in src/bijux_rag/rag/app.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
retrieve ¶
retrieve(
*,
index_path,
query,
top_k=5,
filters=None,
embedder=None,
)
Retrieve candidates from a persisted index.
Source code in src/bijux_rag/rag/app.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
bijux_rag.rag.indexes ¶
Reference indexes.
Two backends are provided out of the box: * NumpyCosineIndex: small/medium corpora, deterministic, dependency-free. * BM25Index: CI-friendly lexical retrieval without model downloads.
Persistence format: msgpack (schema_versioned).
BM25Index dataclass ¶
BM25Index(
chunks,
buckets,
df,
tfs,
doc_len,
avg_dl,
k1=1.2,
b=0.75,
)
Hashed-token BM25 index.
This is a practical, CI-friendly retrieval baseline: - deterministic - no large model downloads - supports metadata filters
NumpyCosineIndex dataclass ¶
NumpyCosineIndex(chunks, vectors, spec)
Dense vector index using cosine similarity.
build_bm25_index ¶
build_bm25_index(*, chunks, buckets=2048, k1=1.2, b=0.75)
Build a hashed-token BM25 index.
Source code in src/bijux_rag/rag/indexes.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | |
build_numpy_cosine_index ¶
build_numpy_cosine_index(*, chunks, embedder)
Build a dense index from chunk texts.
Source code in src/bijux_rag/rag/indexes.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
load_index ¶
load_index(path)
Load an index from disk.
Source code in src/bijux_rag/rag/indexes.py
588 589 590 591 592 593 594 595 596 597 598 | |
bijux_rag.rag.ports ¶
RAG primitives: ports for embedders, indexes, retrieval, and generation.
This module is deliberately dependency-light. Concrete backends live in sibling modules.
The goal is to make bijux-rag actually RAG: ingest -> index -> retrieve (+ optional rerank) -> answer with citations.
Answer dataclass ¶
Answer(text, citations=(), candidates=())
A grounded answer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text | str | Answer text. | required |
citations | tuple[Citation, ...] | Evidence citations. | () |
Candidate dataclass ¶
Candidate(chunk, score, metadata=dict())
A retrieved chunk plus score and non-sensitive metadata.
Citation dataclass ¶
Citation(doc_id, chunk_id, start, end, text=None)
A citation referencing an evidence chunk.
Embedder ¶
Bases: Protocol
Embedder port.
Implementations must be deterministic given the same inputs and configuration.
Generator ¶
Bases: Protocol
Generator port.
Index ¶
Bases: Protocol
Index port.
Indexes are responsible for persistence (save/load) and schema versioning.
Indexer ¶
Bases: Protocol
Indexer port.
Reranker ¶
Bases: Protocol
Reranker port.
bijux_rag.boundaries.web.fastapi_app ¶
FastAPI adapter exposing chunking and RAG endpoints.
pyright: reportUnusedFunction=false¶
create_app ¶
create_app()
Construct a FastAPI app with chunking and RAG endpoints.
Source code in src/bijux_rag/boundaries/web/fastapi_app.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |