r/LocalAIStack • u/crackedgeek • 16m ago
Text-to-Cypher on a 9B model keeps breaking on messy entity names. What do you do?
I'm working with a fully offline LLM setup using 2× NVIDIA A16 GPUs (~15 GB VRAM each), running Qwen 3.8 9B at Q8 through llama.cpp.
The task is translating natural-language questions into Cypher queries for a read-only Neo4j database.
I'm running into two recurring challenges:
- Query generation reliability
The same question can produce different Cypher queries across runs. Most are syntactically correct, but occasionally the model introduces small errors, such as generating ]> instead of ]->, or dropping a digit from an identifier.
I've added an EXPLAIN-based validation step with one retry, which catches most issues, but some failures still slip through.
2. Inconsistent entity matching
The underlying data isn't always normalized. For example, the same vehicle plate might appear as ABC-123 in some records and ABC 123 in others. Place names have similar inconsistencies involving hyphens, spaces and formatting.
Exact matching therefore misses valid records.
There's also an intent-resolution problem: an unfamiliar identifier format can sometimes be interpreted as a continuation of the previous question rather than a new query.
3. Latency
End-to-end response latency is currently around 43 seconds at the median. The pipeline makes two sequential LLM calls per request, and this is becoming a significant bottleneck.
I'm also evaluating Gemma 4 E4B Q8 as an alternative.
I'd love to hear from people who have deployed smaller open-weight models for Text-to-Cypher or structured query generation in production.
A few things I'm particularly interested in:
- How much reliability can you realistically get from validator-and-retry loops?
- Do you use deterministic templates for common query patterns and reserve the LLM for more complex questions?
- Is fine-tuning on domain-specific question-to-Cypher pairs worth the effort?
- How do you handle entity normalization and identifier extraction without relying on the LLM?
- Have you found effective ways to reduce sequential LLM calls without sacrificing accuracy?
I'm particularly interested in approaches that work fully offline, with limited GPU resources and smaller models.
Would appreciate insights from anyone who's tackled this in production.