query
Generate completion using relevant chunks as context.- Sync
- Async
Parameters
query
(str): Query textfilters
(Dict[str, Any], optional): Optional metadata filtersk
(int, optional): Number of chunks to use as context. Defaults to 4.min_score
(float, optional): Minimum similarity threshold. Defaults to 0.0.max_tokens
(int, optional): Maximum tokens in completiontemperature
(float, optional): Model temperatureuse_colpali
(bool, optional): Whether to use ColPali-style embedding model to generate the completion (only works for documents ingested withuse_colpali=True
). Defaults to True.graph_name
(str, optional): Optional name of the graph to use for knowledge graph-enhanced retrievalhop_depth
(int, optional): Number of relationship hops to traverse in the graph (1-3). Defaults to 1.include_paths
(bool, optional): Whether to include relationship paths in the response. Defaults to False.prompt_overrides
(QueryPromptOverrides | Dict[str, Any], optional): Optional customizations for entity extraction, resolution, and query promptsschema
(Type[BaseModel] | Dict[str, Any], optional): Optional schema for structured output, can be a Pydantic model or a JSON schema dictllm_config
(Dict[str, Any], optional): Optional LiteLLM-compatible model configuration (e.g., model name, API key, base URL). Allows overriding the default LLM configuration on a per-query basis. Defaults to None.
Returns
CompletionResponse
: Response containing the completion, source information, and potentially structured output.
Examples
Standard Query
- Sync
- Async
Knowledge Graph Enhanced Query
- Sync
- Async
With Custom Prompt Overrides
- Sync
- Async
CompletionResponse Properties
TheCompletionResponse
object returned by this method has the following properties:
completion
(str | Dict[str, Any] | None): The generated completion text or the structured output dictionary.usage
(Dict[str, int]): Token usage informationsources
(List[ChunkSource]): Sources of chunks used in the completionmetadata
(Dict[str, Any], optional): Additional metadata about the completion. When using a knowledge graph withinclude_paths=True
, this contains graph traversal information.finish_reason
(Optional[str]): Reason the generation finished (e.g., ‘stop’, ‘length’)
ChunkSource Properties
EachChunkSource
object in the sources
list has the following properties:
document_id
(str): ID of the source documentchunk_number
(int): Chunk number within the documentscore
(Optional[float]): Relevance score (if available)
Using Custom LLM Configuration
The
llm_config
parameter is available in SDK version 0.2.5 and later.llm_config
parameter to override the default LLM configuration on a per-query basis. This allows you to use different models, API keys, or other LiteLLM-compatible settings for specific queries.
- Sync
- Async
Using Structured Output
Use theschema
parameter to get the completion response in a structured format according to a Pydantic model or a JSON schema dictionary.
- Sync
- Async