Prompt
I'm building semantic search over product docs and need advice on storage and indexing
Latest observation
A good semantic search setup for product docs usually works best as a hybrid system:
- Vector index for semantic similarity
- Keyword / inverted index for exact terms, SKUs, error codes, product names, etc.
- Metadata filters for product, version, doc type, locale, permissions, date, and so on
Recommended storage model
Store each doc in chunks, not only whole documents.
1) Raw document store
Keep the original content in object storage or a relational DB:
- doc_id
- title
- source URL
- product
- version
- language
- permissions / ACL
- timestamps
- full text
This is your source of truth.
2) Chunk table
Break docs into chunks of roughly 200–800 tokens, with overlap.
Each chunk record should contain:
- chunk_id
- doc_id
- chunk_text
- chunk_order
- section heading / hierarchy
- metadata copied from parent doc
- embedding vector
This is what you actually index for semantic retrieval.
3) Search indexes
Maintain:
- Vector index on chunk embeddings
- Text index for BM25 / keyword search
- Optional reranker stage after retrieval
Indexing strategy
Chunking
For product docs, chunk by structure when possible:
- headings
- paragraphs
- tables
- list items
- code blocks
Avoid splitting:
- API signatures
- steps in procedures
- table rows
- code examples
Use overlap so references near boundaries are preserved.
Embeddings
Generate embeddings for:
- each chunk
- optionally title + heading + chunk text together
Example input:
"Product: X | Version: 3.2 | Section: Authentication | Text: ..."
That often improves retrieval.
Hybrid retrieval
Best practice is:
- Run vector search for semantic matches
- Run keyword search for exact matches
- Merge results
- Apply metadata filters
- Rerank top candidates with a cross-encoder or LLM reranker
This matters a lot for product docs because users often search for:
- error codes
- endpoint names
- configuration flags
- version-specific behavior
- exact UI labels
Storage options
Small to medium scale
If you want simplicity:
- Postgres + pgvector
- plus full-text search in Postgres
- maybe Redis for caching
Good if:
- tens to hundreds of thousands of chunks
- moderate query volume
- you want fewer moving parts
Larger scale / more search-heavy
Use a dedicated vector DB or search engine:
- Elasticsearch / OpenSearch for hybrid keyword + vector
- Pinecone, Weaviate, Milvus, Qdrant for vector search
- store metadata in Postgres or within the search engine
Good if:
- millions of chunks
- high QPS
- need fast filtering and scaling
Metadata design tips
Include these fields in the index:
- product
- doc_type
- version
- locale
- audience
- release date
- availability / access scope
- section path
- source system
This enables queries like:
- “search only v2 docs”
- “exclude internal drafts”
- “only English docs”
- “only docs for Product A”
Practical retrieval pipeline
A strong baseline:
- User query
- Normalize query
- Retrieve top 50 via vector search
- Retrieve top 50 via keyword search
- Combine with weighted scoring
- Filter by metadata/permissions
- Rerank top 10–20
- Return chunks with citations
Important pitfalls
- Indexing entire docs only: hurts recall and citation quality
- Chunking too small: loses context
- Chunking too large: reduces precision
- No metadata filters: results become noisy
- Embedding-only search: misses exact technical terms
- No reranker: top results may be semantically close but not best answer
Suggested starting architecture
If you want a simple, robust first version:
- Postgres for doc storage + metadata
- pgvector for embeddings
- Postgres full-text search for BM25-like keyword retrieval
- background worker for chunking + embedding
- reranker service if needed
Rule of thumb
If your docs are technical/product docs, hybrid search is almost always better than pure vector search.
If you want, I can also give you:
- a concrete schema,
- an indexing pipeline,
- or a stack recommendation for your scale and budget.