or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

agents-workflows.mddata-indexing.mddocument-processing.mdindex.mdllm-integration.mdprompts.mdquery-processing.mdresponse-synthesis.mdretrievers.mdstorage-settings.md

query-processing.mddocs/

0

# Query Processing

1

2

Query engines that orchestrate retrieval and response generation, supporting various strategies from basic retrieval to complex multi-step reasoning and routing.

3

4

## Capabilities

5

6

### Basic Query Engines

7

8

Core query engines that combine retrieval with response synthesis for question-answering.

9

10

```python { .api }

11

class RetrieverQueryEngine:

12

"""

13

Standard retrieval-based query engine.

14

15

Args:

16

retriever: Retriever to use for document retrieval

17

response_synthesizer: Synthesizer for generating responses

18

node_postprocessors: List of node postprocessors

19

callback_manager: Callback manager for event handling

20

"""

21

def __init__(self, retriever, response_synthesizer=None, node_postprocessors=None, callback_manager=None): ...

22

23

def query(self, str_or_query_bundle):

24

"""

25

Query the engine.

26

27

Args:

28

str_or_query_bundle: Query string or QueryBundle object

29

30

Returns:

31

Response: Query response with sources

32

"""

33

34

async def aquery(self, str_or_query_bundle):

35

"""Async version of query."""

36

37

class CitationQueryEngine:

38

"""

39

Query engine that provides source citations in responses.

40

41

Args:

42

retriever: Retriever for document retrieval

43

response_synthesizer: Synthesizer that includes citations

44

**kwargs: Additional arguments

45

"""

46

def __init__(self, retriever, response_synthesizer=None, **kwargs): ...

47

48

def query(self, str_or_query_bundle):

49

"""Query with citation support."""

50

51

class RetryQueryEngine:

52

"""

53

Query engine with retry logic for failed queries.

54

55

Args:

56

query_engine: Base query engine to wrap

57

evaluator: Evaluator to determine if retry is needed

58

max_retries: Maximum number of retry attempts

59

"""

60

def __init__(self, query_engine, evaluator, max_retries=3): ...

61

62

def query(self, str_or_query_bundle):

63

"""Query with automatic retry on failure."""

64

```

65

66

### Advanced Query Engines

67

68

Sophisticated query engines for complex reasoning and multi-step operations.

69

70

```python { .api }

71

class RouterQueryEngine:

72

"""

73

Routes queries to different query engines based on query content.

74

75

Args:

76

selector: Selector to choose appropriate query engine

77

query_engines: List of available query engines

78

**kwargs: Additional arguments

79

"""

80

def __init__(self, selector, query_engines, **kwargs): ...

81

82

def query(self, str_or_query_bundle):

83

"""Route query to appropriate engine."""

84

85

class SubQuestionQueryEngine:

86

"""

87

Breaks complex queries into sub-questions for better handling.

88

89

Args:

90

question_gen: Question generator for creating sub-questions

91

query_engines: List of query engines for sub-questions

92

response_synthesizer: Synthesizer for combining sub-answers

93

**kwargs: Additional arguments

94

"""

95

def __init__(self, question_gen, query_engines, response_synthesizer=None, **kwargs): ...

96

97

def query(self, str_or_query_bundle):

98

"""Query using sub-question decomposition."""

99

100

class MultiStepQueryEngine:

101

"""

102

Multi-step query engine for complex reasoning tasks.

103

104

Args:

105

query_engine: Base query engine

106

query_transform: Transform for iterative refinement

107

index_summary: Summary of the index being queried

108

**kwargs: Additional arguments

109

"""

110

def __init__(self, query_engine, query_transform, index_summary=None, **kwargs): ...

111

112

def query(self, str_or_query_bundle):

113

"""Execute multi-step reasoning."""

114

```

115

116

### Specialized Query Engines

117

118

Query engines for specific data types and use cases.

119

120

```python { .api }

121

class TransformQueryEngine:

122

"""

123

Query engine with query transformation capabilities.

124

125

Args:

126

query_engine: Base query engine to wrap

127

query_transform: Transform to apply to queries

128

transform_metadata: Additional metadata for transformation

129

"""

130

def __init__(self, query_engine, query_transform, transform_metadata=None): ...

131

132

def query(self, str_or_query_bundle):

133

"""Query with transformation."""

134

135

class ComposableGraphQueryEngine:

136

"""

137

Query engine for composable graphs combining multiple indices.

138

139

Args:

140

graph: ComposableGraph to query

141

custom_query_engines: Custom query engines for specific indices

142

**kwargs: Additional arguments

143

"""

144

def __init__(self, graph, custom_query_engines=None, **kwargs): ...

145

146

def query(self, str_or_query_bundle):

147

"""Query across multiple indices."""

148

```

149

150

### Pandas Integration

151

152

Query engines for natural language queries over pandas DataFrames.

153

154

```python { .api }

155

class PandasQueryEngine:

156

"""

157

Natural language query engine for pandas DataFrames.

158

159

Args:

160

df: Pandas DataFrame to query

161

instruction_str: Instructions for query interpretation

162

**kwargs: Additional arguments

163

"""

164

def __init__(self, df, instruction_str=None, **kwargs): ...

165

166

def query(self, str_or_query_bundle):

167

"""

168

Execute natural language query on DataFrame.

169

170

Args:

171

str_or_query_bundle: Natural language query

172

173

Returns:

174

Response: Query results with DataFrame operations

175

"""

176

```

177

178

### SQL Integration

179

180

Query engines for natural language to SQL translation and execution.

181

182

```python { .api }

183

class NLSQLTableQueryEngine:

184

"""

185

Natural language to SQL query engine.

186

187

Args:

188

sql_database: SQL database wrapper

189

tables: List of table names to query

190

**kwargs: Additional arguments

191

"""

192

def __init__(self, sql_database, tables=None, **kwargs): ...

193

194

def query(self, str_or_query_bundle):

195

"""

196

Execute natural language SQL query.

197

198

Args:

199

str_or_query_bundle: Natural language query

200

201

Returns:

202

Response: Query results from database

203

"""

204

```

205

206

## Response Synthesizers

207

208

Components that generate coherent responses from retrieved context.

209

210

```python { .api }

211

def get_response_synthesizer(response_mode="compact", **kwargs):

212

"""

213

Factory function for creating response synthesizers.

214

215

Args:

216

response_mode: Synthesis mode ("refine", "compact", "tree_summarize", "simple_summarize")

217

**kwargs: Additional arguments

218

219

Returns:

220

BaseSynthesizer: Response synthesizer instance

221

"""

222

223

class TreeSummarize:

224

"""Tree-based response synthesis with hierarchical summarization."""

225

def __init__(self, **kwargs): ...

226

227

def synthesize(self, query, nodes, **kwargs):

228

"""Synthesize response using tree summarization."""

229

230

class Refine:

231

"""Iterative response refinement synthesis."""

232

def __init__(self, **kwargs): ...

233

234

def synthesize(self, query, nodes, **kwargs):

235

"""Synthesize response using iterative refinement."""

236

237

class CompactAndRefine:

238

"""Compact context then refine response."""

239

def __init__(self, **kwargs): ...

240

241

def synthesize(self, query, nodes, **kwargs):

242

"""Synthesize response with compacting and refinement."""

243

244

class SimpleSummarize:

245

"""Simple concatenation-based synthesis."""

246

def __init__(self, **kwargs): ...

247

248

def synthesize(self, query, nodes, **kwargs):

249

"""Synthesize response with simple concatenation."""

250

```

251

252

## Query Bundle

253

254

```python { .api }

255

class QueryBundle:

256

"""

257

Query representation with optional embeddings.

258

259

Args:

260

query_str: Query string

261

image_path: Optional image path for multimodal queries

262

embedding: Optional query embedding

263

custom_embedding_strs: Custom strings for embedding

264

"""

265

def __init__(self, query_str, image_path=None, embedding=None, custom_embedding_strs=None): ...

266

267

@property

268

def query_str(self):

269

"""Query string."""

270

271

@property

272

def embedding(self):

273

"""Query embedding vector."""

274

```

275

276

## Response Schema

277

278

```python { .api }

279

class Response:

280

"""

281

Response object with source tracking.

282

283

Args:

284

response: Response text

285

source_nodes: List of source nodes used

286

metadata: Additional response metadata

287

"""

288

def __init__(self, response=None, source_nodes=None, metadata=None): ...

289

290

@property

291

def response(self):

292

"""Response text."""

293

294

@property

295

def source_nodes(self):

296

"""Source nodes used for response."""

297

298

def get_formatted_sources(self, length=100):

299

"""

300

Get formatted source text.

301

302

Args:

303

length: Maximum length per source

304

305

Returns:

306

str: Formatted source information

307

"""

308

```