---
title: Search and discovery
summary: How book search works, what consistency to expect, and how to use filters.
version: 1.0.0
type: guides
order: 2
badges:
  - content: Guide
    backgroundColor: teal
    textColor: teal
---

**Audience & Outcome:** This guide is for frontend developers, AI agent builders, and operators integrating with BookWorm's catalog discovery endpoints. You will learn how structured browsing and free-text search execute, what consistency guarantees apply, and how to isolate search symptoms.

[[service|catalog-api]] serves book discovery through two complementary query paths: structured browsing against [[container|catalog-database]] and free-text discovery combining [[container|catalog-vector]] candidate retrieval with authoritative PostgreSQL hydration. Both Storefront and [[service|mcp-server]] share this architecture so displayed prices, availability, and cover links always come from the primary database.

## Context and motivation

Customers discover books in two distinct ways: navigating structured facets (categories, authors, publishers, price ranges, sorting) and entering natural-language search queries. Relational SQL filtering handles exact facets well but misses semantic intent, while serving prices directly from a search index risks exposing stale commercial data during price updates or book retirements.

BookWorm combines relational accuracy with vector recall by treating [[container|catalog-vector]] as a **candidate-ranking projection** and [[container|catalog-database]] as the **authoritative hydration source**.

## How it works

Every discovery request enters [[service|catalog-api]] (via REST for Storefront or internal gRPC from [[service|mcp-server]] for conversational AI) and branches based on whether a free-text search term is present.

This visual shows how structured browsing queries the primary database directly while free-text search embeds the query, ranks candidates in the vector store, and hydrates authoritative rows from PostgreSQL.

<MermaidFileLoader file="mermaids/02-search-and-discovery-diagram-1.mmd" />

### Query paths

| Discovery mode              | Entry condition                                                                         | Execution path                                                                                                                                                                                                                  | Authoritative data source                                                              |
| :-------------------------- | :-------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------- |
| **Structured browse**       | Category, publisher, author, price bounds, sort, or page parameters with no search term | Queries [[container\|catalog-database]] directly and caches pages in [[container\|catalog-cache]]                                                                                                                               | [[container\|catalog-database]]                                                        |
| **Free-text hybrid search** | Search term provided (with optional facets and paging)                                  | Embeds query via Microsoft Foundry, runs hybrid vector + keyword search in [[container\|catalog-vector]] for candidate book IDs, hydrates rows from [[container\|catalog-database]], applies filters/paging, and caches results | [[container\|catalog-vector]] candidates hydrated from [[container\|catalog-database]] |

### Consistency expectations

:::note
New or edited books appear in direct lookups and structured browse immediately, but appear in free-text search only after [[service|catalog-ingestion]] processes the pending queue (triggered every 5 minutes by [[service|scheduler-service]]).
:::

- **Authoritative commercial details:** Prices, discount prices, availability, rating summaries, and freshly signed cover SAS URLs always come from [[container|catalog-database]] and [[container|catalog-blob]], never from vector index payloads.
- **Brief deletion transition window:** When a [[entity|book]] is soft-deleted, [[container|catalog-vector]] may still return its ID as a candidate until the next [[service|catalog-ingestion]] batch removes the vector. Hydration against [[container|catalog-database]] filters out soft-deleted books so retired titles never appear in returned results.

### Separating discovery symptoms

Because discovery touches [[container|catalog-vector]], [[container|catalog-cache]], and expiring [[container|catalog-blob]] SAS URLs, isolate symptoms before escalating:

- **New or edited book missing from text search only:** Indicates ingestion lag — follow the Vector Index Lag runbook.
- **Old price or metadata shown after an update:** Indicates stale cache — follow the Stale Cache or Redis Outage runbook.
- **Book cover image returns HTTP `403` or `404`:** Indicates an expired SAS URL or missing blob — follow the Broken Book Images runbook.

<AccordionGroup>
<Accordion title="Design trade-offs and alternatives considered">

| Decision                                           | Benefits                                                                                              | Costs and limits                                                                    |
| :------------------------------------------------- | :---------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------- |
| **Vector candidate lookup + PostgreSQL hydration** | Guarantees authoritative prices, soft-delete filtering, and live SAS URLs on every search response    | Adds a relational lookup step after vector retrieval                                |
| **Asynchronous background vector indexing**        | Keeps catalog writes fast and shields [[service\|catalog-api]] from embedding or vector store outages | Creates a brief lag window before new or edited books appear in free-text search    |
| **Hashed cache keys for list and search pages**    | Reduces repeated embedding and database load on popular queries                                       | Cached pages can reflect brief staleness until tag invalidation or TTL expiry (30m) |

**Rejected alternatives:**

- **PostgreSQL full-text search alone:** Struggles with semantic and conversational discovery queries from Storefront and [[service|chat-api]].
- **Serving book prices directly from vector payloads:** Risks displaying outdated prices or retired books due to eventual consistency.

</Accordion>
</AccordionGroup>

## Related documentation

- [[flow|product-ingestion]] — How [[service|scheduler-service]], Kafka, and [[service|catalog-ingestion]] keep [[container|catalog-vector]] synchronized.
- [[flow|agent-orchestration]] — How [[service|chat-api]] queries Catalog discovery through [[service|mcp-server]].
- [[adr|adr-002-hybrid-vector-search-qdrant]] — Architectural decision for hybrid vector and keyword search.
