Menu

The one-word bug that kills keyword search in your Postgres RAG
📰

The one-word bug that kills keyword search in your Postgres RAG

DEV Community: postgres·Ayush Gupta·9 days ago
#c3ePrHqM
#devtopostgresql#devto#dev#search#terms
Reading 0:00
15s threshold

If your RAG runs on Postgres + pgvector, you have probably added full-text search next to vector search, because every production write-up says pure vector search misses exact identifiers: error codes, SKUs, version strings, product names.

Anthropic's own example is a user searching for "Error code TS-999": embeddings find content about error codes in general, while keyword search finds the exact match (Contextual Retrieval).

So you write this:

sql SELECT * FROM chunks WHERE tsv @@ websearch_to_tsquery ( 'english' , : question ) ORDER BY ts_rank_cd ( tsv , websearch_to_tsquery ( 'english' , : question )) DESC LIMIT 50 ;

Enter fullscreen mode

Exit fullscreen mode

It looks right. It passes your test query. And for most real questions it returns nothing.

Why

websearch_to_tsquery joins every word with AND. A user asks "how many requests per minute does the growth plan allow?".…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.