Skip to main content

queryIntentRouter

Workspace API


Workspace API / services/queryIntentRouter

services/queryIntentRouter

Interfaces

HistoryMessage

Defined in: services/queryIntentRouter.ts:30

Simplified history message for intent classification

Properties

role

role: "user" | "assistant"

Defined in: services/queryIntentRouter.ts:31

content

content: string

Defined in: services/queryIntentRouter.ts:32

chunks?

optional chunks: RAGChunk[]

Defined in: services/queryIntentRouter.ts:33

timestamp?

optional timestamp: Date

Defined in: services/queryIntentRouter.ts:34


TargetReference

Defined in: services/queryIntentRouter.ts:40

Target reference for TARGETED intent

Properties

documentFilename?

optional documentFilename: string

Defined in: services/queryIntentRouter.ts:41

pageNumbers?

optional pageNumbers: number[]

Defined in: services/queryIntentRouter.ts:42

chunkId?

optional chunkId: string

Defined in: services/queryIntentRouter.ts:43


IntentClassification

Defined in: services/queryIntentRouter.ts:49

Intent classification result

Properties

intent

intent: QueryIntent

Defined in: services/queryIntentRouter.ts:50

confidence

confidence: "high" | "medium" | "low"

Defined in: services/queryIntentRouter.ts:51

reasoning?

optional reasoning: string

Defined in: services/queryIntentRouter.ts:52

targetReference?

optional targetReference: TargetReference

Defined in: services/queryIntentRouter.ts:54

For TARGETED intent: which document/chunk to expand on

method

method: "heuristic" | "llm"

Defined in: services/queryIntentRouter.ts:56

Classification method used

latencyMs

latencyMs: number

Defined in: services/queryIntentRouter.ts:58

Time taken for classification (ms)


ClassifyIntentOptions

Defined in: services/queryIntentRouter.ts:64

Options for intent classification

Properties

heuristicsOnly?

optional heuristicsOnly: boolean

Defined in: services/queryIntentRouter.ts:66

Skip LLM and use heuristics only (for testing/fallback)

timeoutMs?

optional timeoutMs: number

Defined in: services/queryIntentRouter.ts:68

Timeout for LLM classification (default: 3000ms)

Type Aliases

QueryIntent

QueryIntent = "RETRIEVE" | "HISTORY_ONLY" | "TARGETED" | "HYBRID"

Defined in: services/queryIntentRouter.ts:25

Query intent classification result

Functions

classifyQueryIntent()

classifyQueryIntent(query, history, options?): Promise<IntentClassification>

Defined in: services/queryIntentRouter.ts:374

Classify query intent using hybrid approach (LLM-heavy)

Strategy:

  1. Fast heuristic check for DEFINITE new topics only (~20% of queries)
  2. Everything else goes to LLM classification (~80% of queries)

This ensures nuanced follow-ups are handled correctly at the cost of ~100-150ms latency for most queries.

Parameters

query

string

User's query

history

HistoryMessage[]

Conversation history (messages)

options?

ClassifyIntentOptions

Classification options

Returns

Promise<IntentClassification>

Intent classification result


messagesToHistory()

messagesToHistory(messages): HistoryMessage[]

Defined in: services/queryIntentRouter.ts:416

Convert database messages to history format for classification

Parameters

messages

Message[]

Returns

HistoryMessage[]