ElastranAI: Building an Elastic-Powered AI Assistant
The development story of ElastranAI - an AI assistant with native Elasticsearch integration for semantic search and intelligent document retrieval.
What happens when you combine conversational AI with enterprise-grade search?
ElastranAI was our answer—an AI assistant that doesn’t just respond to queries but searches, retrieves, and synthesizes information from massive document collections.
The Origin
Traditional AI assistants have a context problem. They’re limited to:
- Whatever’s in their training data (often outdated)
- The current conversation history
- Manually provided context
But organizations have terabytes of institutional knowledge. ElastranAI connects AI to that knowledge.
Architecture
ElastranAI Architecture
├── Frontend (Next.js)
│ ├── Conversational interface
│ ├── Document viewer
│ └── Search visualization
├── Backend (FastAPI)
│ ├── Query processing
│ ├── AI orchestration
│ └── Response synthesis
├── Elasticsearch
│ ├── Document indexing
│ ├── Semantic search
│ └── Result ranking
└── AI Layer
├── Query understanding
├── Document analysis
└── Response generation
Why Elasticsearch?
Elasticsearch provides:
- Speed: Sub-second search across millions of documents
- Relevance: BM25 + semantic ranking
- Scalability: Horizontal scaling for enterprise volumes
- Flexibility: Full-text, structured, and vector search
Why Not Just Use RAG?
Standard RAG (Retrieval-Augmented Generation) has limitations:
- Naive chunking loses context
- Vector-only search misses exact matches
- No query understanding layer
ElastranAI uses a hybrid approach:
- Parse and understand the query
- Multi-strategy search (keyword + semantic + filters)
- Intelligent result re-ranking
- Contextual response synthesis
Key Features
Semantic Query Understanding
Before searching, we understand what you’re actually asking:
async def understand_query(query: str) -> QueryIntent:
"""
Classify query intent and extract parameters:
- Is this a factual question or exploratory?
- What entities are mentioned?
- What time range is relevant?
- What document types should be prioritized?
"""
intent = await classify_intent(query)
entities = extract_entities(query)
filters = infer_filters(intent, entities)
return QueryIntent(
type=intent,
entities=entities,
filters=filters,
search_strategy=select_strategy(intent)
)Hybrid Search
Combine multiple search strategies:
def hybrid_search(query: str, intent: QueryIntent) -> SearchResults:
# Strategy 1: Keyword search with BM25
keyword_results = elastic.search(
query={"match": {"content": query}},
size=20
)
# Strategy 2: Semantic search with vectors
embedding = generate_embedding(query)
vector_results = elastic.search(
knn={"field": "embedding", "query_vector": embedding},
size=20
)
# Strategy 3: Filtered search based on entities
filtered_results = elastic.search(
query={"bool": {"must": intent.filters}},
size=20
)
# Fusion: Combine and re-rank
return fuse_and_rank(keyword_results, vector_results, filtered_results)Contextual Response Synthesis
Don’t just return documents—synthesize answers:
async def synthesize_response(query: str, documents: list) -> Response:
"""
Generate response that:
- Directly answers the question
- Cites sources appropriately
- Acknowledges uncertainty when present
- Suggests follow-up questions
"""
context = prepare_context(documents)
response = await llm.generate(
system="You are a research assistant with access to documents...",
user=f"Query: {query}\n\nRelevant documents:\n{context}"
)
return Response(
answer=response.text,
sources=extract_citations(response, documents),
confidence=calculate_confidence(response, documents),
follow_ups=suggest_follow_ups(query, documents)
)Performance Results
Search Latency
| Operation | Latency |
|---|---|
| Query parsing | 50ms |
| Keyword search | 30ms |
| Vector search | 80ms |
| Result fusion | 20ms |
| Total search | 180ms avg |
Quality Metrics
| Metric | Score |
|---|---|
| Answer accuracy | 91% |
| Source relevance | 88% |
| Response helpfulness | 4.3/5.0 |
Scale Testing
Successfully tested with:
- 5 million documents indexed
- 100 concurrent queries
- 99.9% uptime over 30 days
Real-World Use Cases
Internal Knowledge Base
Scenario: Engineering team with 10,000+ documents Problem: Finding relevant information takes hours Solution: Index all docs in ElastranAI
Result:
- Query: “How do we handle rate limiting in production?”
- Response: Synthesized answer with 3 relevant doc citations
- Time: 2 seconds vs 30+ minutes manual search
Customer Support
Scenario: Support team handling technical questions Problem: Agents spend 40% of time searching for answers Solution: ElastranAI connected to product documentation
Result:
- 40% reduction in average handle time
- Consistent answers across agents
- Automatic citation of official docs
Legal Document Review
Scenario: Law firm with case file archive Problem: Finding precedent takes days Solution: Semantic search across case history
Result:
- Query: “Cases involving breach of fiduciary duty by trustees”
- Returns relevant cases with key passages highlighted
- Days of research compressed to minutes
Lessons Learned
1. Query Understanding Is Critical
Without understanding what the user actually wants, even the best search engine returns irrelevant results.
2. Hybrid Search Beats Pure Approaches
Neither keyword-only nor vector-only search is sufficient. The fusion approach consistently outperforms.
3. Citations Build Trust
Users trust AI responses more when sources are visible. Always show your work.
4. Latency Matters More Than You Think
Every 100ms of search latency reduces user satisfaction. We optimized aggressively.
What’s Next
Current roadmap:
- Multi-modal search (images, PDFs, videos)
- Real-time index updates
- Query analytics and optimization suggestions
- Fine-tuned embedding models per domain
ElastranAI represents our approach to knowledge-augmented AI. For related technologies, see MCP orchestration and Universal Knowledge Synthesizer.