Autocomplete Plugin Feature¶
Overview¶
The Autocomplete Plugin provides intelligent, database-aware Cypher query autocomplete suggestions. Unlike generic autocomplete, this feature uses actual database schema information (labels, properties, relationship types) to provide context-aware suggestions.
Architecture¶
Backend Components¶
- Plugin Action:
heimdall_watcher_autocomplete_suggest - Location:
plugins/heimdall/plugin.go(Watcher plugin) -
Queries the database for:
- All node labels (
CALL db.labels() YIELD label) - All relationship types (
CALL db.relationshipTypes() YIELD relationshipType) - Sample properties from nodes (limited to 50 for performance)
- All node labels (
-
API Endpoint:
/api/bifrost/autocomplete - Location:
pkg/heimdall/handler.go - Method: POST
- Request:
{ "query": "MATCH (n", "cursor_position": 10 } -
Response:
{ "suggestion": "...", "schema": { "labels": [...], "properties": [...], "relTypes": [...] } } -
SLM Integration
- If the action doesn't provide a suggestion, the handler uses the SLM to generate one
- The SLM receives the current query plus schema context (labels, properties, relTypes)
- Prompt includes instructions to add
LIMIT 25if missing
Frontend Components¶
- QueryAutocomplete Component
- Location:
ui/src/components/browser/QueryAutocomplete.tsx - Calls
/api/bifrost/autocompleteendpoint - Debounced (800ms) to avoid excessive API calls
-
Displays suggestions in a dropdown below the query editor
-
Integration
- Integrated into
QueryPanel.tsx - Toggleable via lightning bolt icon
- Keyboard navigation support (Arrow keys, Enter, Escape)
How It Works¶
-
User Types Query: User starts typing a Cypher query (e.g.,
MATCH (n) -
Debounce: After 800ms pause, the component sends the partial query to
/api/bifrost/autocomplete -
Backend Processing:
- Action queries database for schema (labels, properties, relTypes)
- If SLM is available, generates completion using schema context
-
Returns both the suggestion and schema info
-
Suggestion Display:
- If a valid suggestion is returned, it appears in a dropdown
- User can accept via click, Enter key, or continue typing
Benefits¶
✅ Database-Aware: Uses actual labels, properties, and relationship types from your database
✅ Context-Aware: Suggestions are based on what actually exists in your graph
✅ Intelligent: SLM generates completions with full schema context
✅ Performance: Debounced requests prevent excessive API calls
✅ User-Friendly: Keyboard navigation and toggleable feature
API Details¶
Endpoint¶
Request¶
Response¶
{
"suggestion": "MATCH (n) RETURN n LIMIT 25",
"schema": {
"labels": ["Person", "File", "Document"],
"properties": ["name", "age", "title"],
"relTypes": ["KNOWS", "OWNS", "AUTHORED"]
}
}
Example Flow¶
- User types:
MATCH (n:Per - Backend queries: Gets all labels, finds "Person" exists
- SLM generates:
MATCH (n:Person) RETURN n LIMIT 25 - UI displays suggestion
- User presses Enter → Query is completed
Future Enhancements¶
- Property value suggestions based on context
- Relationship pattern suggestions
- Multi-line query support
- Syntax error detection and correction
- Query optimization suggestions