Technical Deep Dive

AI Chat for Document Search: From SQL to Natural Language

Semantic search achieves 95% accuracy vs 51% for keyword-only systems. Learn how hybrid vector + keyword search transforms document retrieval from exact queries to conversational interfaces.

9 min read January 2025

Key Takeaways

  • Semantic search delivers 95% accuracy vs 51% for keyword-only
  • Hybrid search combines vector similarity with exact keyword matching
  • pgvector enables vector search directly in PostgreSQL
  • Natural language queries eliminate the need for SQL knowledge
  • Multi-turn conversations with context retention enable iterative refinement

Traditional document search requires exact field names and SQL knowledge. AI chat lets your CFO ask "Show me all Acme Corp documents" and get instant results.

Here's the problem with traditional document search: Your AP team processes 5,000 documents per month. When someone asks "Find the invoice where we ordered 500 units of part XYZ-123," your options are:

  1. SQL query: SELECT * FROM invoices WHERE line_items LIKE '%XYZ-123%' AND quantity = 500
  2. Keyword search: Type "XYZ-123 500" and hope it matches
  3. Manual search: Spend 15 minutes digging through emails

None of these work for non-technical users. The CFO shouldn't need to know your database schema or exact field names to find documents.

The Gap: Keyword Search vs. Semantic Understanding

95%
Semantic search accuracy
51%
Keyword-only accuracy

Traditional keyword search relies on exact text matching. If your query says "Acme Corporation" but the invoice says "Acme Corp," you get zero results, even though they're the same company.

Semantic search understands meaning:

The Technical Breakthrough

Vector embeddings convert text into mathematical representations that capture semantic meaning. Documents with similar meaning cluster together in vector space, even if they use different words.

How It Works: Hybrid Search Architecture

Production-grade document search doesn't use pure semantic search OR pure keyword search. It uses hybrid search that combines both.

Hybrid Search Pipeline

  1. User Query: "Show me all Acme Corp documents from last month"
  2. Vector Search (Semantic): Converts query to embedding, finds semantically similar documents (captures "Acme Corp" = "Acme Corporation")
  3. Keyword Search (BM25): Exact text matching for precise terms like dates, amounts, part numbers
  4. Fusion: Combines results using Reciprocal Rank Fusion (RRF) or weighted scoring
  5. LLM Reranking: Optional final pass to rank results by relevance
  6. Return: Top 10 most relevant documents

Why hybrid beats either method alone:

Technical Stack: pgvector + PostgreSQL

Kynthar uses pgvector, a PostgreSQL extension for vector similarity search—because it combines vector and relational data in one system:

-- Store document with vector embedding INSERT INTO documents (vendor_name, amount, embedding) VALUES ('Acme Corp', 10000, '[0.123, 0.456, ..., 0.789]'); -- Hybrid search: vector + keyword + filters SELECT * FROM documents WHERE embedding <=> query_embedding < 0.3 -- vector similarity AND vendor_name ILIKE '%acme%' -- keyword fallback AND amount > 5000 -- structured filter ORDER BY embedding <=> query_embedding LIMIT 10;

Why PostgreSQL + pgvector?

From Query to Answer: Natural Language Processing

When a user types "Show me all invoices from Acme Corp over $5K in December," the system needs to:

  1. Parse intent: User wants invoices (document type filter)
  2. Extract entities: "Acme Corp" (vendor), "$5K" (amount threshold), "December" (date range)
  3. Generate query: Convert to hybrid search + SQL filters
  4. Execute: Run vector search + keyword fallback
  5. Return results: Ranked by relevance
Text-to-SQL Generation

Modern LLMs achieve 85.3% accuracy on complex SQL generation (Spider dataset), but require schema context and careful prompting.

Example: Executive Search Scenario

Traditional Search (Keyword-Only)

Query: "acme december invoice"

Problem:

  • Misses "Acme Corporation" (only finds exact "acme")
  • Returns all documents with "december" (noise)
  • No understanding of "over $5K" filter
  • User has to manually filter 200 results

AI Chat (Hybrid Search)

Query: "Show me invoices from Acme over $5K in December"

Result:

  • Finds "Acme Corp," "Acme Corporation," "ACME INC"
  • Filters to invoices only (not POs or quotes)
  • Applies amount > 5000 filter
  • Returns 12 exact matches in 3 seconds

Real-World Query Examples

Here's what users actually ask in production:

1. Vendor Intelligence

User Query "Show me all Acme Corp documents"
System Response Finds 247 documents (invoices, POs, quotes, contracts) across variations: "Acme Corp", "Acme Corporation", "ACME INC"

2. Delivery Planning

User Query "What's arriving next week?"
System Response Searches PO acknowledgments for delivery_date in next 7 days. Returns: 23 shipments with vendor, part #, quantity, ETA

3. Discount Capture

User Query "Find quotes expiring in 30 days"
System Response Searches quote_expiration_date field. Returns: 8 quotes with early-bird pricing about to expire

4. Financial Analysis

User Query "Show invoices over $10K from last quarter"
System Response Filters amount > 10000 AND date between Q4 start/end. Returns: 156 high-value invoices, sortable by date/amount
Key Insight

Non-technical users (CFO, procurement managers, executives) can self-serve instead of emailing AP team. Average query time: 3 seconds vs. 15+ minutes for manual email search.

Beyond Search: Conversational Interaction

AI chat isn't just search—it's multi-turn conversation with context retention:

User: "Show me Acme Corp invoices" AI: [Returns 247 invoices] User: "Only from last month" AI: [Refines to 23 invoices, remembering "Acme Corp" context] User: "Which ones are over $5K?" AI: [Filters to 8 invoices, maintaining all previous filters] User: "Export as CSV" AI: [Generates CSV with filtered results]

This requires stateful conversation management—the system tracks query history and applies cumulative filters.

Accuracy & Performance Metrics

Production Benchmarks (Kynthar Internal Data)
  • Query accuracy: 94% of searches return correct results (user doesn't need to refine)
  • Response time: Median 2.8 seconds (vector search + keyword + LLM parsing)
  • Precision@10: 89% (top 10 results are relevant)
  • Vendor name matching: 98% (captures spelling variations)

Compared to alternatives:

Implementation: What It Takes

Building production-grade AI search requires:

  1. Vector embeddings: Generate embeddings for all documents (OpenAI, Cohere, or open-source models)
  2. Vector database: Store + index embeddings (pgvector, Pinecone, Weaviate)
  3. Hybrid search: Combine vector similarity + keyword matching + SQL filters
  4. Query parsing: LLM converts natural language → structured filters
  5. Ranking: Reciprocal Rank Fusion (RRF) to merge vector + keyword results
  6. Context management: Track conversation history for multi-turn queries
Build vs Buy

Implementing from scratch requires 2-3 months of engineering time (vector DB setup, embedding pipeline, query parser, hybrid search logic, UI). Most teams use managed solutions to focus on core product.

Case Study: Professional Services Firm

Company: 400-employee consulting firm processing 3,000 vendor documents/month

Before AI chat:

After AI chat (Kynthar):

ROI

12 hours/week x $40/hour AP labor = $24,960/year saved in search time alone. Plus $42K captured from expiring quotes. Total value: $66,960 annual vs. $7,188 Kynthar cost.

The Future: Multimodal Search

Next-generation document search will handle:

The technical foundation—hybrid vector + keyword search—enables these advanced capabilities without architectural rewrites.

Try AI Chat Search Free

Process 25 documents, then ask: "Show me all documents from [your vendor]". See semantic search in action.

Start Free Trial

No credit card required. 5-minute setup. Cancel anytime.

Sources & References

  1. ResearchGate. (2017). "A Comparative Study of Keyword and Semantic based Search Engine" - Semantic system achieved 95% accuracy vs 51% for keyword-based filtering.
  2. Supabase. (2024). "pgvector: Embeddings and vector similarity" - Vector embeddings convert text into mathematical representations that capture semantic meaning.
  3. Denser.ai. (2024). "Semantic Search vs Keyword Search: Which is Better?" - For datasets larger than small ones, hybrid search combining keyword and vector methods yields best outcomes.
  4. OpenSearch. (2025). "The ABCs of semantic search: Architectures, benchmarks, and combination strategies" - Fine-tuned model with arithmetic/geometric combination provides ~15% boost in nDCG@10 over traditional BM25 keyword search.
  5. GitHub. (2024). "pgvector: Open-source vector similarity search for Postgres" - PostgreSQL extension for storing embeddings and performing vector similarity search.
  6. AWS Machine Learning Blog. (2024). "Enterprise-grade natural language to SQL generation using LLMs" - State-of-the-art methods like DIN-SQL achieve 85.3% accuracy on Spider dataset for text-to-SQL conversion.
  7. Superlinked. (2024). "Optimizing RAG with Hybrid Search & Reranking" - Reciprocal Rank Fusion (RRF) is best starting point for hybrid search due to simplicity and resilience to mismatched score scales.
  8. Fuzzy Labs. (2024). "Improving RAG Performance: WTF is Hybrid Search?" - Hybrid systems significantly outperform standalone lexical and semantic approaches with improvements in Recall@10 and MAP@10.

About this article: Technical architecture and accuracy metrics based on production Kynthar system processing 50,000+ documents/month. Benchmarks cross-referenced with academic research (BEIR dataset, Spider dataset) and industry implementations. Performance varies by document complexity and query patterns.