---
title: Vector index lag
summary: Diagnose and recover when new or edited books do not appear in text search.
version: 1.0.0
type: runbooks
order: 1
badges:
  - content: Runbook
    backgroundColor: orange
    textColor: orange
---

## Trigger / Symptom & Blast Radius

Newly created, edited, or deleted books appear in direct lookups and structured browse, but are missing or outdated in free-text search. [[service|catalog-ingestion]] is an internal background worker triggered every 5 minutes by [[service|scheduler-service]] over [[channel|scheduler.process-vector-batch]] to sync up to 200 queued rows per batch from [[container|catalog-database]] into [[container|catalog-vector]]. Blast radius is limited to free-text search discovery; checkout and authoritative catalog browsing remain unaffected.

<Admonition type="danger">
	Run a full index rebuild only after confirmed vector store data loss or an indexed-field schema
	change. Never manually delete pending queue rows from [[container|catalog-database]] to hide a
	backlog.
</Admonition>

## Pre-Flight Check

Verify [[service|catalog-ingestion]] container health and check pending queue depth in [[container|catalog-database]]:

```bash
az containerapp show --name <SERVICE_NAME> --resource-group <RESOURCE_GROUP> --query "properties.runningStatus" -o tsv
```

```sql
SELECT count(*) AS pending_books, min(updated_at) AS oldest_pending_update, clock_timestamp() - min(updated_at) AS oldest_pending_age
FROM pending_vector_updates;
```

## Quick Recovery Procedure

<Steps>
<Step title="Verify Scheduler and Kafka delivery">

Open Quartz Dashboard at `/quartz` (requires `admin` role) and confirm the 5-minute vector batch job is firing without errors, then inspect consumer lag on [[channel|scheduler.process-vector-batch]]:

```bash
az containerapp logs show --name <SERVICE_NAME> --resource-group <RESOURCE_GROUP> --tail 100
```

If running locally in Aspire, ensure the [[service|scheduler-service]] resource is started manually in the Aspire Dashboard.

</Step>
<Step title="Check for a stuck PostgreSQL advisory lock">

If [[service|catalog-ingestion]] logs show skipped runs (`0` processed items), check whether an orphaned session holds the ingestion advisory lock (`740031001`) in [[container|catalog-database]]:

```sql
SELECT l.pid, a.usename, a.application_name, a.state, a.query_start
FROM pg_locks l
JOIN pg_stat_activity a ON a.pid = l.pid
WHERE l.locktype = 'advisory' AND l.objid = 740031001;
```

Terminate only a verified dead or hung session:

```sql
SELECT pg_terminate_backend(<STUCK_PID>);
```

</Step>
<Step title="Verify embedding provider and vector store health">

Check [[service|catalog-ingestion]] logs for Microsoft Foundry embedding errors or [[container|catalog-vector]] connection timeouts. Unacknowledged rows remain safely queued in [[container|catalog-database]] and retry automatically on the next 5-minute cycle.

</Step>
<Step title="Drain backlog or trigger approved full rebuild">

Once dependencies are healthy, trigger the vector batch job in Quartz Dashboard to drain a large backlog faster. Only if [[container|catalog-vector]] suffered data loss, re-enqueue all books:

```sql
INSERT INTO pending_vector_updates (book_id)
SELECT id FROM books
ON CONFLICT (book_id) DO UPDATE SET revision = gen_random_uuid(), updated_at = clock_timestamp();
```

</Step>
</Steps>

## Verification

Re-run the pending queue query in [[container|catalog-database]] and confirm `pending_books` trends to `0`:

```sql
SELECT count(*) AS pending_books FROM pending_vector_updates;
```

Expected output:

```text
 pending_books
---------------
             0
```

## Rollback / Escalation

- **Rollback:** If a full rebuild saturates embedding quotas, pause the trigger in Quartz Dashboard (`/quartz`) until quota recovers, then resume.
- **Escalation:** Escalate persistent embedding, vector store, or ingestion failures to [[team|platform-engineering-team]] or [[team|catalog-experience-team]] with queue age and sanitized logs.

<AccordionGroup>
<Accordion title="Troubleshooting edge cases">

| Symptom                                    | Cause                                                            | Fix                                                          |
| :----------------------------------------- | :--------------------------------------------------------------- | :----------------------------------------------------------- |
| `pending_books` is `0` but search is stale | Search result is cached in [[container\|catalog-cache]]          | Wait for cache expiry or follow the stale cache runbook      |
| Jobs never fire locally                    | [[service\|scheduler-service]] requires explicit start in Aspire | Start [[service\|scheduler-service]] in the Aspire Dashboard |
| Batch aborts with incomplete embeddings    | Microsoft Foundry rate limit or auth failure                     | Verify Managed Identity RBAC and Foundry quota               |

</Accordion>
</AccordionGroup>

## Related documentation

- [[flow|product-ingestion]] — End-to-end vector indexing pipeline.
- [[adr|adr-003-database-queue-for-vector-indexing]] — Why Catalog uses a transactional database queue.
