Real World Example

Where It Is Used

  • E-commerce search (Flipkart, Amazon, Myntra style): keyword matching for brands and model numbers plus semantic matching for "shoes for monsoon", then a learned re-ranker.
  • Answer engines (Perplexity style): web search, re-ranking of passages, and answers with numbered citations.
  • Support bots (Freshworks, Zoho Desk style): hybrid search over help articles and past tickets.

Hybrid Search in One SQL Query (pgvector)

ShopEase keeps policy chunks in PostgreSQL with a tsvector column for keywords and a vector column for embeddings, and fuses both with RRF inside the database.

WITH keyword AS (
  SELECT id, ROW_NUMBER() OVER (ORDER BY ts_rank_cd(tsv, query) DESC) AS rnk
  FROM policy_chunks, plainto_tsquery('english', $1) AS query
  WHERE tsv @@ query
  ORDER BY rnk LIMIT 30
),
semantic AS (
  SELECT id, ROW_NUMBER() OVER (ORDER BY embedding <=> $2::vector) AS rnk
  FROM policy_chunks
  ORDER BY embedding <=> $2::vector LIMIT 30
)
SELECT c.id, c.title, c.body,
       COALESCE(1.0 / (60 + k.rnk), 0) + COALESCE(1.0 / (60 + s.rnk), 0) AS rrf
FROM keyword k
FULL OUTER JOIN semantic s ON s.id = k.id
JOIN policy_chunks c ON c.id = COALESCE(k.id, s.id)
ORDER BY rrf DESC
LIMIT 8;

The Python Pipeline

def answer(question: str, history: list[dict]) -> str:
    q = standalone_query(history, question)                      # 1. rewrite (Haiku)
    q_vec = vo.embed([q], model="voyage-3.5", input_type="query").embeddings[0]
    rows = db.execute(HYBRID_SQL, (q, q_vec)).fetchall()         # 2. hybrid search + RRF
    top = vo.rerank(q, [r.body for r in rows], model="rerank-2.5", top_k=4).results   # 3. re-rank
    context = "\n".join(f'<doc id="{rows[r.index].id}">{r.document}</doc>' for r in top)
    resp = client.messages.create(                               # 4. answer with citations
        model="claude-sonnet-5-5",
        max_tokens=1000,
        system="Answer only from the docs. Cite doc ids like [12]. If the docs do not answer, say so.",
        messages=[{"role": "user", "content": f"<docs>\n{context}\n</docs>\n\nQuestion: {question}"}],
    )
    return next(b.text for b in resp.content if b.type == "text")

Run it

python ask.py "Can I return earbuds I paid for with COD?"

Example output

Yes. Earbuds count as electronics, so you get a 7-day replacement (not a refund) if
they are unused and in the original box [12]. For COD orders, any refund is paid to
your bank account or UPI ID after pickup [31].