AI & LLM Search

Torque integrates large language models into search three ways: conversational answers over your results, natural-language query translation, and automatic embedding for semantic search. All three work with any OpenAI-compatible endpoint - hosted or self-hosted. No local model runtime is required.

Conversational Search

Conversational search retrieves the top hits for a question and generates a grounded answer from them, with durable multi-turn history.

1. Register a conversation model

POST /conversations/models
Content-Type: application/json
X-TYPESENSE-API-KEY: YOUR_API_KEY

{
  "id": "gpt-support",
  "model_name": "openai/gpt-5",
  "api_key": "OPENAI_API_KEY",
  "max_bytes": 16384,
  "system_prompt": "You are a helpful product assistant.",
  "history_collection": "conversation_history"
}
FieldRequiredDescription
model_nameYesModel identifier passed to the chat endpoint (e.g., openai/gpt-5)
max_bytesYesMaximum bytes of retrieved documents included in the prompt
api_keyNoAPI key for the LLM endpoint
system_promptNoPrepended to the answer prompt
history_collectionNoCollection storing conversation history. Auto-created as ts_conversation_history_{id} when omitted; history survives restarts.
ttlNoConversation lifetime in seconds
vllm_urlNoBase URL of a self-hosted OpenAI-compatible server - /v1/chat/completions is appended automatically

Full CRUD is available: GET /conversations/models, GET/PUT/DELETE /conversations/models/{id}.

2. Search with conversation=true

GET /collections/products/documents/search?\
q=which laptops have the best battery life?&query_by=title,description&\
conversation=true&conversation_model_id=gpt-support
X-TYPESENSE-API-KEY: YOUR_API_KEY

The response includes the normal search results plus a conversation object with the generated answer and a conversation_id. Pass conversation_id on the next request to continue the conversation - follow-up questions are automatically rewritten into standalone queries so retrieval stays accurate across turns.

Streaming

Add conversation_stream=true to stream the answer as server-sent events, wire-compatible with Typesense's streaming format: delta events with the growing message, a [DONE] sentinel, and the complete search-results JSON as the final event.

Natural-Language Search

NL search translates a free-form question into structured search parameters (q, filter_by, sort_by) before the search executes. The model is prompted with your collection's schema and sampled facet values, so generated filters use values that actually exist in your data.

1. Register an NL search model

POST /nl_search_models
Content-Type: application/json
X-TYPESENSE-API-KEY: YOUR_API_KEY

{
  "id": "nl-products",
  "model_name": "openai/gpt-5",
  "api_key": "OPENAI_API_KEY",
  "max_bytes": 16384
}

Optional fields: api_url (self-hosted OpenAI-compatible endpoint), system_prompt, temperature. Full CRUD at /nl_search_models and /nl_search_models/{id}.

2. Search with nl_query=true

GET /collections/products/documents/search?\
q=cheap laptops under 500 dollars sorted by rating&\
nl_query=true&nl_model_id=nl-products
X-TYPESENSE-API-KEY: YOUR_API_KEY

The translated parameters are echoed in the response's request_params, so you can see exactly what was searched. NL search chains with conversational search: a follow-up question is first rewritten to a standalone question, then translated to structured parameters, then retrieved and answered.

Auto-Embedding

Declare an embed config on a float[] vector field and Torque fills the embedding at import time from the configured source fields - no client-side model code:

{
  "name": "products",
  "fields": [
    {"name": "title", "type": "string"},
    {"name": "description", "type": "string"},
    {
      "name": "embedding",
      "type": "float[]",
      "num_dim": 1536,
      "embed": {
        "from": ["title", "description"],
        "model_config": {
          "model_name": "openai/text-embedding-3-small",
          "api_key": "OPENAI_API_KEY"
        }
      }
    }
  ]
}
FieldDescription
fromSource fields whose text is concatenated and embedded
model_config.model_nameopenai/<model> uses the OpenAI endpoint; any other name requires url
model_config.urlOpenAI-compatible embeddings endpoint (self-hosted models)
model_config.api_keyAPI key for the embedding endpoint

num_dim is required and the dimensions returned by the embedding endpoint are validated against it. Embed fields are implicitly optional - documents never supply the vector themselves.

Query-time embedding

Search semantically without sending a vector - the query text is embedded server-side via the field's configured model:

GET /collections/products/documents/search?\
q=laptop for travel&query_by=title&vector_query=embedding:([], k:10)
X-TYPESENSE-API-KEY: YOUR_API_KEY

This enables hybrid search (text + semantic, blended with reciprocal rank fusion) with zero client-side embedding code. See Vector Search for hybrid ranking details.

Licensing

Vector search (including auto-embedding) requires a license. Conversational and NL search models call your own LLM endpoint - Torque does not proxy or meter tokens.