The AI service (port 8100) powers HxNexus natural language queries, semantic embedding generation, and vector similarity search. It calls the configured AI backend with structured system prompts and uses pgvector for nearest-neighbour retrieval.
| Method | Path | Description |
|---|---|---|
POST | /api/v1/nexus/query | NL query with optional case context. Returns structured answer + sources. |
POST | /api/v1/nexus/stream | Streaming SSE response — same as query but token-by-token |
POST | /api/v1/embed | Generate embedding for a text string |
POST | /api/v1/embed/batch | Batch embedding generation (up to 100 texts) |
GET | /api/v1/similar | Find similar entities by text query. Params: ?text=...&top_k=5&entity_type=stage |
GET | /health | Health check — returns {"status":"ok","model":"claude-sonnet-4-6"} |
# Query with case context curl -s -X POST http://localhost:8100/api/v1/nexus/query \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "question": "What is the current status of this case and what step is next?", "case_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "access_group_id": "group-finance" }' # Response shape { "answer": "CASE-0042 is currently in the Review stage, assigned to agent1...", "sources": ["case_events", "stages"], "sql": "SELECT ... FROM cases WHERE id = '...'", // surfaced for transparency "confidence": 0.94 }
# Stream response (Server-Sent Events) curl -N -s -X POST http://localhost:8100/api/v1/nexus/stream \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"question": "Summarise the top 5 open cases by SLA urgency"}' # Each SSE event: data: {"token": "The", "done": false} data: {"token": " five", "done": false} data: {"token": "...", "done": false} data: {"done": true, "answer": "..."}
# Single embedding curl -s -X POST http://localhost:8100/api/v1/embed \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"text": "customer identity verification document upload"}' # Batch embedding (up to 100) curl -s -X POST http://localhost:8100/api/v1/embed/batch \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"texts": ["loan application intake", "credit assessment review", "final approval stage"]}'
HxNexus constructs a system prompt containing the full HxGraph context (serialised graph nodes + edges) and the user's access group schema on each request. This system prompt can be 10,000–50,000 tokens for complex installations. AI prompt caching allows the system prompt to be cached server-side for 5 minutes.
| Metric | Without Caching | With Caching (typical) |
|---|---|---|
| Input tokens per query | 10,000–50,000 | 200–500 (only the question) |
| Cache hit rate | — | 80–95% in steady state |
| Latency | High | ~70% reduction on cache hits |
| Variable | Required | Default | Description |
|---|---|---|---|
ANTHROPIC_API_KEY | Yes | — | AI provider API key (e.g. Anthropic API key for Claude backend) |
AI_MODEL | No | claude-sonnet-4-6 | AI model identifier |
EMBED_MODEL | No | sentence-transformers/all-MiniLM-L6-v2 | Embedding model for semantic similarity |
PGVECTOR_ENABLED | No | true | Enable pgvector similarity search |
DATABASE_URL | Yes | — | Same PostgreSQL DSN as case-service |
JWT_SECRET | Yes | — | Shared secret for JWT validation |