Prompt
building a search layer for our chatbot
Latest observation
Oct 23, 2026
OpenAI APIWeb search: off
Nice — a search layer can make a chatbot dramatically more useful.
A good search layer usually handles three things:
- Find the right information
- Rank it well
- Package it for the LLM so the answer is grounded and concise
Typical architecture
1) Ingestion
- Pull data from docs, wiki, tickets, DBs, PDFs, webpages, etc.
- Clean and normalize text
- Split into chunks
- Add metadata:
- source
- title
- timestamp
- permissions
- tags
- entity IDs
2) Indexing
Usually you want hybrid search:
- Keyword/BM25 for exact matches, names, IDs, error codes
- Vector search for semantic similarity
- Optional reranker to improve top results
3) Query understanding
Before searching:
- detect intent
- rewrite/expand the query if needed
- extract entities and filters
- apply security/permission filters
4) Retrieval pipeline
A solid flow is:
- query rewrite
- hybrid retrieve top 20–100
- rerank top 10–20
- dedupe / merge chunks
- pass best evidence to the chatbot
5) Answer generation
The LLM should:
- answer only from retrieved context when possible
- cite sources
- say “I don’t know” when evidence is weak
- ask clarifying questions if the query is ambiguous
Key design choices
Chunking
- Too large: retrieval gets noisy
- Too small: context gets fragmented
A common starting point:
- 200–500 tokens per chunk
- 10–20% overlap
Metadata filtering
Very important if you have:
- user-specific content
- team-specific content
- time-sensitive content
Hybrid retrieval
Best default for most chatbot search layers.
Reranking
Worth it if quality matters. Even a strong embedding search benefits from reranking.
Evaluation
You’ll want to measure:
- recall@k
- MRR / nDCG
- grounded answer quality
- citation accuracy
- latency
Recommended MVP
If you want a practical first version:
- Store chunks in:
- a vector DB
- a keyword search index
- Use hybrid retrieval
- Add simple reranking
- Attach source metadata
- Return top 3–5 chunks to the LLM
- Force citation-based answering
Common pitfalls
- No metadata filters
- Over-chunking or under-chunking
- Only vector search, no keyword search
- No reranker
- Not testing with real user queries
- Letting the LLM answer without enough evidence
If you want, I can help you with any of these next:
- Design the full architecture
- Choose a stack (Elasticsearch/OpenSearch, pgvector, Pinecone, etc.)
- Build a retrieval pipeline
- Write chunking/indexing code
- Design evaluation metrics
- Create an end-to-end chatbot search flow
If you want, tell me:
- what your data sources are
- expected scale
- whether you need permissions
- what stack you’re using
and I’ll propose a concrete design.