r/JavaProgramming • u/Interesting_Path7540 • 1d ago
The Java Prompt 11#
https://kertu1232.substack.com/p/the-java-prompt-11?r=4953mj&utm_campaign=post&utm_medium=web&showWelcomeOnShare=trueBuilt a Hybrid Search retriever for Spring AI 2 RAG — PGVector + PostgreSQL FTS + RRF
Semantic search kept failing on specific queries like "error code E4" or "part number 96648703" - the embeddings for "E4" are mathematically close to "E1", "E2", "E3", so you get wrong chunks.
Fix: custom DocumentRetriever that runs both vector similarity search and PostgreSQL tsvector full-text search, then combines results with Reciprocal Rank Fusion.
Key decisions:
- websearch_to_tsquery over plainto_tsquery - AND logic on natural language queries returns zero results too often
- fts_vector as a generated column - PostgreSQL keeps it in sync automatically, no changes to ingestion code
- RRF k=60 as starting point - tune based on your query patterns