Document Retrieval
query
Generate completion using relevant chunks as context
query
Generate completion using relevant chunks as context.
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 dict
Returns
CompletionResponse
: Response containing the completion, source information, and potentially structured output.
Examples
Standard Query
Knowledge Graph Enhanced Query
With Custom Prompt Overrides
CompletionResponse Properties
The CompletionResponse
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
Each ChunkSource
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 Structured Output
Use the schema
parameter to get the completion response in a structured format according to a Pydantic model or a JSON schema dictionary.
Was this page helpful?