MCPcopy Index your code
hub / github.com/docker/docker-agent / Query

Method Query

pkg/rag/manager.go:239–425  ·  view source on GitHub ↗

Query searches for relevant documents using all configured strategies If multiple strategies are configured, results are combined using the fusion strategy

(ctx context.Context, query string)

Source from the content-addressed store, hash-verified

237// Query searches for relevant documents using all configured strategies
238// If multiple strategies are configured, results are combined using the fusion strategy
239func (m *Manager) Query(ctx context.Context, query string) (results []database.SearchResult, err error) {
240 // Start a `retrieval {rag_name}` span per the OTel GenAI semconv.
241 // The query text itself is sensitive so we never capture it on the
242 // span here — content capture is gated by a separate environment
243 // variable in a later commit and emitted via a span event then.
244 ctx, retSpan := genai.StartRetrieval(ctx, "rag", m.name, false, "")
245 defer func() {
246 if err != nil {
247 retSpan.RecordError(err, "")
248 }
249 retSpan.SetResultCount(len(results))
250 retSpan.End()
251 }()
252
253 slog.DebugContext(ctx, "[RAG Manager] Starting query",
254 "rag_name", m.name,
255 "num_strategies", len(m.strategies),
256 "query_length", len(query))
257
258 // Single retrieval strategy
259 if len(m.strategies) == 1 {
260 for strategyName, strategyImpl := range m.strategies {
261 strategyCfg := m.strategyConfigs[strategyName]
262
263 slog.DebugContext(ctx, "[RAG Manager] Single strategy query",
264 "rag_name", m.name,
265 "strategy", strategyName,
266 "strategy_limit", strategyCfg.Limit,
267 "strategy_threshold", strategyCfg.Threshold)
268
269 // Assign to the function's named returns (note `=`, not
270 // `:=`) so the deferred span closure sees the live values
271 // even if a future change replaces the explicit
272 // `return X, Y` form below with a bare `return`.
273 results, err = strategyImpl.Query(ctx, query, strategyCfg.Limit, strategyCfg.Threshold)
274 if err != nil {
275 slog.ErrorContext(ctx, "[RAG Manager] Strategy query failed",
276 "rag_name", m.name,
277 "strategy", strategyName,
278 "error", err)
279 return nil, err
280 }
281
282 slog.DebugContext(ctx, "[RAG Manager] Single strategy results",
283 "rag_name", m.name,
284 "strategy", strategyName,
285 "num_results", len(results))
286
287 // Apply reranking if configured
288 results = m.rerank(ctx, query, results)
289
290 if limit := m.config.Results.Limit; limit > 0 && len(results) > limit {
291 slog.DebugContext(ctx, "[RAG Manager] Truncating to global result limit",
292 "rag_name", m.name,
293 "strategy", strategyName,
294 "before", len(results),
295 "after", limit)
296 results = results[:limit]

Callers

nothing calls this directly

Calls 11

rerankMethod · 0.95
deduplicateResultsMethod · 0.95
StartRetrievalFunction · 0.92
getStrategyNamesFunction · 0.85
SetResultCountMethod · 0.80
RecordErrorMethod · 0.65
QueryMethod · 0.65
FuseMethod · 0.65
EndMethod · 0.45
NewMethod · 0.45

Tested by

no test coverage detected