Indexing and integration API
For a complete, runnable workflow and its delivery guarantees, see the
indexing guide. Imports below are from omnichunk unless a
module is specified. Method signatures and defaults are generated from source.
Local chunk store
ChunkStore(path, collection="default") opens a SQLite file at path; use a
context manager or call close(). collection names the logical chunk collection.
query(filepath) returns stored chunks for that path. index(root, ...) reprocesses
matching files; sync(root, ...) skips unchanged files and configurations. Both
return SyncResult. root is the directory to scan; glob (default "**/*")
selects files, exclude is a sequence of exclusion patterns, include_hidden
defaults to False, and encoding defaults to "utf-8". Supply either a configured chunker or chunker keyword options for processing;
passing both raises ValueError. A successful scan may remove missing
files within its previously owned scope; consult the guide before changing filters.
SyncResult exposes files_scanned, files_skipped, files_updated and
files_deleted counts, removed_chunk_ids for downstream deletions, and
diffs keyed by filepath. Delete the removed IDs before upserting each diff's
added chunks; refresh locations for unchanged chunks when needed. Migration
requires separate source and nonexistent destination paths, with an optional
collection name. Its MigrationResult reports file/chunk counts, id_map and
whether reindexing is required.
omnichunk.store.ChunkStore
SQLite-backed named collection of chunked documents.
Directory deletion is limited to a previously completed scan with the same resolved root, glob, exclusions and hidden-file policy. A partial file scan or a new filter never deletes siblings. Collections are independent.
One explicit transaction covers a complete sync, including deletions. A read/provider/serialization/database failure propagates and preserves the last good state so a subsequent sync retries it. The write lock is held while processing; use separate connections for concurrent readers.
Source code in src/omnichunk/store/chunk_store.py
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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
query(filepath)
Return this collection's chunks in byte/index source order.
Source code in src/omnichunk/store/chunk_store.py
188 189 190 191 192 193 194 195 | |
index(root, *, glob='**/*', exclude=None, include_hidden=False, encoding='utf-8', chunker=None, **chunker_options)
Re-chunk all matching files, with the same deletion safety as sync.
Source code in src/omnichunk/store/chunk_store.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
sync(root, *, glob='**/*', exclude=None, include_hidden=False, encoding='utf-8', chunker=None, **chunker_options)
Skip only files with unchanged content and processing configuration.
Source code in src/omnichunk/store/chunk_store.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
omnichunk.store.SyncResult
dataclass
A committed scan. Exceptions return no success result and roll back the scan.
Apply removed_chunk_ids before upserting each diff's added chunks.
Same-ID payload changes are included in both for compatibility. Unchanged
chunks may have moved: refresh their location metadata without re-embedding.
Source code in src/omnichunk/store/chunk_store.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
omnichunk.store.migrate_legacy_store(source, destination, *, collection='default')
Copy a v1 database to a new v2 path without modifying the old database.
The destination must not exist. Complete metadata present in old JSON is retained; already-lost metadata cannot be recreated. Converted records have no scan ownership and an empty configuration fingerprint, forcing reindexing on the next sync. Missing-source records remain recoverable until an explicit new index is built. The returned ID map supports a separate vector rebuild.
Source code in src/omnichunk/store/chunk_store.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
omnichunk.store.MigrationResult
dataclass
Offline copy result; rebuild embeddings for the new occurrence IDs.
Source code in src/omnichunk/store/chunk_store.py
94 95 96 97 98 99 100 101 102 | |
omnichunk.store.LegacyStoreError
Bases: ValueError
An old or unknown database must not be mutated by the v2 store.
Source code in src/omnichunk/store/chunk_store.py
90 91 | |
Journal and delivery
IndexJournal(path) uses its own SQLite file, separate from ChunkStore.
plan(sources, *, target_id, model_revision, ...) produces an IndexPlan
without writing to a vector backend. Each IndexSource has a stable source_id,
source revision, a tuple of chunks, and optional JSON-compatible metadata.
collection defaults to "default"; target_id identifies the backend target;
model_revision is required and preprocessing_revision defaults to
"identity-v1"; together they identify embedding behavior.
use_contextualized_text=True selects the contextualized embedding payload;
set it to False for raw chunk text. Set scope and
complete_scope=True only for a complete scan; delete_sources explicitly removes
the specified source IDs. Enqueue the plan before delivery.
deliver(sink, embed, *, collection="default", batch_size=64, max_batches=None,
retry_failed=False) sends bounded batches. embed accepts a sequence of texts
and returns corresponding vectors; it can be omitted when no uncached embeddings
are needed. max_batches limits work per call; retry_failed permits retry of
previously permanent or unclassified failures. The sink's target_id must match
the plan. DeliveryResult reports completed and pending work; status() reports
the journal's current state. Delivery is at least once, so sinks must be idempotent.
For IndexPlan, base_generation is the collection generation used to create
the plan; upserts contains IndexRecord values to write, while removed_ids
lists IDs to delete. added_ids, metadata_update_ids, embedding_invalidations
and unchanged_ids classify the comparison with the previous state. plan_id
identifies the plan and schema_version versions its JSON representation.
DeliveryBatch contains the collection, target, idempotency key, vector
upserts, deletes and operation IDs. A custom IndexSink.apply(batch) must
return a DeliveryReceipt with the matching key and exactly those operation IDs.
DeliveryResult counts acknowledged and pending operations, model calls and reused
embeddings; completed indicates whether delivery finished. IndexStatus
contains the current generation, pending plan and operation counts, last error,
and whether that error is retryable.
omnichunk.indexing.IndexJournal
A separate delivery database; existing ChunkStore databases are untouched.
A collection is bound to one caller-owned target identity and vector dimension. One pending plan serializes each collection. External calls occur under a SQLite write transaction; use independent connections for workers, never a reentrant journal callback. A sink must make every operation idempotent.
Source code in src/omnichunk/indexing/journal.py
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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 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 545 546 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 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | |
records(*, collection='default')
Return the last fully acknowledged generation, including source metadata.
Source code in src/omnichunk/indexing/journal.py
213 214 215 216 217 218 219 220 221 | |
plan(sources, *, collection='default', target_id, model_revision, preprocessing_revision='identity-v1', use_contextualized_text=True, scope=None, complete_scope=False, delete_sources=())
Build a dry-run plan without committing source state or calling a model.
Exhaust the supplied scan before planning. complete_scope removes only
missing members of that named scope with no other scope owner. An explicit
deletion removes all ownership. A failed/incomplete iterator cannot delete.
Source code in src/omnichunk/indexing/journal.py
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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
enqueue(plan)
Persist a validated plan and its outbox atomically; safe to retry.
Source code in src/omnichunk/indexing/journal.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 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 545 546 547 548 549 550 551 552 | |
deliver(sink, embed=None, *, collection='default', batch_size=64, max_batches=None, retry_failed=False)
Deliver bounded batches; exact acknowledgements checkpoint durable work.
A remote success followed by a crash is replayed. Prepared vectors were
committed before remote I/O, so recovery reuses them. Unknown failures
require explicit retry_failed=True; retryable failures remain eligible.
This method does not sleep or promise distributed exactly-once delivery.
Source code in src/omnichunk/indexing/journal.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
prune_embeddings(*, collection='default')
Remove vectors unused by acknowledged records; reject pending plans.
Source code in src/omnichunk/indexing/journal.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | |
omnichunk.indexing.IndexSource
dataclass
Source code in src/omnichunk/indexing/models.py
98 99 100 101 102 103 | |
omnichunk.indexing.IndexPlan
dataclass
Source code in src/omnichunk/indexing/models.py
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 298 299 300 301 302 303 304 305 | |
to_json()
Serialize an integrity-checked plan; post-creation mutation is rejected.
Source code in src/omnichunk/indexing/models.py
196 197 198 199 200 | |
omnichunk.indexing.IndexRecord
dataclass
Source code in src/omnichunk/indexing/models.py
106 107 108 109 110 111 112 113 | |
omnichunk.indexing.VectorRecord
dataclass
Source code in src/omnichunk/indexing/models.py
116 117 118 119 120 121 122 123 | |
omnichunk.indexing.DeliveryBatch
dataclass
Source code in src/omnichunk/indexing/models.py
126 127 128 129 130 131 132 133 | |
omnichunk.indexing.DeliveryReceipt
dataclass
Source code in src/omnichunk/indexing/models.py
136 137 138 139 | |
omnichunk.indexing.DeliveryResult
dataclass
Source code in src/omnichunk/indexing/models.py
159 160 161 162 163 164 165 166 | |
omnichunk.indexing.IndexStatus
dataclass
Source code in src/omnichunk/indexing/models.py
148 149 150 151 152 153 154 155 156 | |
omnichunk.indexing.IndexSink
Bases: Protocol
Source code in src/omnichunk/indexing/models.py
142 143 144 145 | |
omnichunk.indexing.IndexConflictError
Bases: ValueError
A plan no longer matches the collection generation or pending delivery.
Source code in src/omnichunk/indexing/models.py
16 17 | |
omnichunk.indexing.JournalSchemaError
Bases: ValueError
The database is not a supported indexing journal.
Source code in src/omnichunk/indexing/models.py
20 21 | |
omnichunk.indexing.RetryableSinkError
Bases: RuntimeError
Delivery failed transiently and can be retried by the next deliver call.
Source code in src/omnichunk/indexing/models.py
24 25 | |
omnichunk.indexing.PermanentSinkError
Bases: RuntimeError
Delivery needs intervention before an explicit retry_failed=True call.
Source code in src/omnichunk/indexing/models.py
28 29 | |
omnichunk.indexing.AcknowledgementError
Bases: PermanentSinkError
A sink did not acknowledge exactly the submitted batch.
Source code in src/omnichunk/indexing/models.py
32 33 | |
Backend and framework adapters
QdrantSink(client, *, target_id, collection_name, dimensions) uses a
caller-configured Qdrant client and an existing physical collection. PgvectorSink
accepts a caller-owned connection, target_id, dimensions and optional SQL
table (default "omnichunk_vectors"); call initialize() explicitly with
an idle connection and sufficient database privileges. Both require a positive
vector dimension. Qdrant retrieval should filter by logical collection and
application-owned access metadata.
The guide includes setup recipes.
omnichunk.indexing.sinks.QdrantSink
Write to a caller-provisioned Qdrant collection using qdrant-client 1.x.
The collection must have a single unnamed dense vector of dimensions.
Logical index collections share the physical collection safely through UUID
mapping. Retrieval must filter both collection and caller-owned access
attributes, for example metadata.acl. target_id must permanently
identify this endpoint and physical collection in the application's journal.
If one ID occurs in both deletes and upserts, deletion precedes replacement.
Source code in src/omnichunk/indexing/sinks.py
126 127 128 129 130 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 | |
omnichunk.indexing.sinks.PgvectorSink
Commit collection-scoped writes through a caller-owned psycopg 3 connection.
Call initialize() explicitly to create the vector extension and table.
The connection must be idle at entry so a receipt cannot precede an outer
transaction's commit. Use autocommit connections for application reads.
target_id must identify the database/schema/table in the journal.
Source code in src/omnichunk/indexing/sinks.py
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 | |
initialize()
Explicitly provision the extension/table; requires database privileges.
Source code in src/omnichunk/indexing/sinks.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
omnichunk.indexing.sinks.qdrant_point_id(collection, record_id)
Map a logical collection/record pair to the UUID used for writes/deletes.
Source code in src/omnichunk/indexing/sinks.py
24 25 26 | |
Framework adapters require their respective optional dependencies.
OmniChunkTextSplitter and OmniChunkNodeParser accept an options mapping
with the same chunk options, filepath="document.txt", optional
levels for hierarchical output, and use_contextualized_text=False to select
raw text by default. The LlamaIndex parser requires JSON-serializable options and
does not support id_func. OmniChunkIngestionPipeline accepts LlamaIndex
pipeline arguments and requires OmniChunkNodeParser as its first transformation;
it creates one by default.
See the framework guide for
document identities, caching and complete examples.
omnichunk.integrations.langchain.OmniChunkTextSplitter
Bases: TextSplitter
Split source documents once while preserving IDs, metadata and citations.
options are ordinary Chunker options. levels optionally emits all
hierarchy levels with links in reserved metadata['omnichunk']. Supply
document IDs or per-document source_id metadata for identity across edits.
Without them, inline text uses a content-hash identity. Raw text is the default;
contextualized output is explicit and its source ranges still address raw text.
Source code in src/omnichunk/integrations/langchain.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
omnichunk.integrations.llamaindex.OmniChunkNodeParser
Bases: NodeParser
Cacheable native parser with exact citations and optional hierarchy.
Options must be JSON serializable for ingestion cache identity. Use named tokenizers rather than callbacks. Metadata remains available to filtering but is excluded from model rendering; embedding input is exactly the selected raw/contextualized payload. Metadata storage does not enforce authorization.
Source code in src/omnichunk/integrations/llamaindex.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
omnichunk.integrations.llamaindex.OmniChunkIngestionPipeline
Bases: IngestionPipeline
Native pipeline whose cache distinguishes identical text from different sources.
LlamaIndex's ordinary cache key excludes document IDs and can return another
document's cached citations. This pipeline copies inputs and fingerprints
their complete JSON source records before cache lookup. Its first transform
must be :class:OmniChunkNodeParser; subsequent transforms remain caller-owned.
Internal identity metadata is removed by the parser and never embedded.
Source code in src/omnichunk/integrations/llamaindex.py
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 | |