---
id: catalog-ingestion
name: Catalog Ingestion
version: 1.0.0
summary: |
  Internal background worker that reads pending Catalog book updates and
  synchronizes semantic search vectors in Qdrant.
styles:
  icon: /icons/compute/function.svg
writesTo:
  - id: catalog-database
  - id: catalog-vector
readsFrom:
  - id: catalog-database
owners:
  - catalog-experience-team
badges:
  - content: Internal
    backgroundColor: gray
    textColor: gray
  - content: Background worker
    backgroundColor: blue
    textColor: blue
receives:
  - id: ProcessVectorBatchIntegrationEvent
    version: 1.0.0
    from:
      - id: scheduler.process-vector-batch
        version: 1.0.0
repository:
  language: C#
  url: "https://github.com/foxminchan/BookWorm"
---

## Service Responsibility & Boundary

Catalog Ingestion is an internal background worker within the [[domain|catalog]] domain that reads coalesced book mutations from [[container|catalog-database]], generates semantic embeddings, and upserts or removes records in [[container|catalog-vector]]. Authoring APIs and synchronous search queries remain owned by [[service|catalog-api]], while recurring schedule management is delegated to [[service|scheduler-service]].

## Service Profile

| Property                                  | Value                                                                                                                      |
| :---------------------------------------- | :------------------------------------------------------------------------------------------------------------------------- |
| **Bounded Context / Domain**              | [[domain\|catalog]]                                                                                                        |
| **Owner Team**                            | [[team\|catalog-experience-team]]                                                                                          |
| **Runtime Style**                         | Async Worker (Kafka-triggered serverless function)                                                                         |
| **Public / Gateway Exposure**             | Internal Only (no HTTP or gRPC surface)                                                                                    |
| **Authentication & Authorization Policy** | Internal worker; Azure Managed Identity RBAC for AI embedding generation                                                   |
| **Owned Data Store(s)**                   | Reads/acknowledges pending queue in [[container\|catalog-database]]; writes derived index in [[container\|catalog-vector]] |
| **Key Resilience / Idempotency Pattern**  | Distributed advisory lock for single-writer exclusivity and revision-checked queue acknowledgment                          |

## Contracts & Data Ownership

Catalog Ingestion owns no authoritative business entities. It processes bounded batches of up to 200 pending updates from [[container|catalog-database]] on each scheduled trigger and updates [[container|catalog-vector]] accordingly.

:::note
If a book is modified concurrently while a batch is in flight, its pending queue revision changes and the worker leaves the row queued for the next cycle—preventing stale embeddings from overwriting newer edits.
:::

<MessageTable format="all" limit={10} showChannels={true} />

<Accordion title="Batch Execution & Failure Semantics">
	- **Single-writer exclusivity:** Acquires an exclusive advisory lock on
	[[container|catalog-database]]; overlapping triggers exit immediately without duplicate work. -
	**Retry on downstream failure:** If embedding generation or vector store writes fail,
	unacknowledged rows remain queued and are retried automatically on the next 5-minute trigger.
</Accordion>

## Architecture Visualizations & Specifications

### Vector Indexing Flow

<MermaidFileLoader file="mermaids/CatalogIngestion-diagram-1.mmd" />

### Service Interactions

<NodeGraph />

## Attached Resources & Related Docs

- [[doc|platform/006-api-and-contracts]] — Consolidated service and messaging directory.
- [[service|catalog-api]] — Authoritative Catalog service that enqueues vector updates.
- [[service|scheduler-service]] — Scheduler dispatching periodic batch triggers.
- [[container|catalog-database]] — Authoritative catalog store and pending update queue.
- [[container|catalog-vector]] — Derived vector search collection.
