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

Method Initialize

pkg/rag/manager.go:155–235  ·  view source on GitHub ↗

Initialize indexes all documents using all configured strategies Each strategy indexes its own document set (shared + strategy-specific) Strategies are initialized in parallel for better performance

(ctx context.Context)

Source from the content-addressed store, hash-verified

153// Each strategy indexes its own document set (shared + strategy-specific)
154// Strategies are initialized in parallel for better performance
155func (m *Manager) Initialize(ctx context.Context) (err error) {
156 tracer := otel.Tracer("github.com/docker/docker-agent/pkg/rag")
157 ctx, span := tracer.Start(ctx, "rag.initialize",
158 trace.WithSpanKind(trace.SpanKindInternal),
159 trace.WithAttributes(
160 attribute.String(genai.AttrDataSourceID, m.name),
161 attribute.Int("cagent.rag.num_strategies", len(m.strategies)),
162 ),
163 )
164 defer func() {
165 if err != nil {
166 span.RecordError(err)
167 span.SetStatus(codes.Error, err.Error())
168 }
169 span.End()
170 }()
171
172 slog.DebugContext(ctx, "[RAG Manager] Starting initialization",
173 "rag_name", m.name,
174 "num_strategies", len(m.strategies))
175
176 // Initialize strategies in parallel to avoid blocking
177 type result struct {
178 strategyName string
179 err error
180 }
181
182 resultsChan := make(chan result, len(m.strategies))
183
184 for strategyName, strategyImpl := range m.strategies {
185 strategyCfg := m.strategyConfigs[strategyName]
186
187 go func() {
188 slog.DebugContext(ctx, "[RAG Manager] Initializing strategy",
189 "rag_name", m.name,
190 "strategy", strategyName,
191 "num_docs", len(strategyCfg.Docs),
192 "chunk_size", strategyCfg.Chunking.Size,
193 "chunk_overlap", strategyCfg.Chunking.Overlap,
194 "respect_word_boundaries", strategyCfg.Chunking.RespectWordBoundaries,
195 "code_aware", strategyCfg.Chunking.CodeAware)
196
197 start := time.Now()
198 err := strategyImpl.Initialize(ctx, strategyCfg.Docs, strategyCfg.Chunking)
199 indexDuration := time.Since(start)
200 slog.DebugContext(ctx, "[RAG Manager] Strategy indexing duration",
201 "rag_name", m.name,
202 "strategy", strategyName,
203 "duration", indexDuration)
204 if err != nil {
205 slog.ErrorContext(ctx, "[RAG Manager] Strategy initialization failed",
206 "rag_name", m.name,
207 "strategy", strategyName,
208 "error", err)
209 } else {
210 slog.InfoContext(ctx, "[RAG Manager] Strategy initialized successfully",
211 "rag_name", m.name,
212 "strategy", strategyName)

Callers

nothing calls this directly

Calls 7

NowMethod · 0.80
StartMethod · 0.65
RecordErrorMethod · 0.65
InitializeMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45
EndMethod · 0.45

Tested by

no test coverage detected