feat(tools): add background embedding queue for thoughts
Some checks failed
CI / build-and-test (push) Failing after -29m22s

* Implement QueueThought method in BackfillTool for embedding generation
* Update CaptureTool to utilize embedding queuer for failed embeddings
* Add EmbeddingStatus field to Thought type for tracking embedding state
This commit is contained in:
2026-04-11 23:37:53 +02:00
parent 1d4dbad33f
commit 4d107cb87e
5 changed files with 61 additions and 13 deletions

View File

@@ -51,6 +51,30 @@ func NewBackfillTool(db *store.DB, provider ai.Provider, sessions *session.Activ
return &BackfillTool{store: db, provider: provider, sessions: sessions, logger: logger}
}
// QueueThought queues a single thought for background embedding generation.
// It is used by capture when the embedding provider is temporarily unavailable.
func (t *BackfillTool) QueueThought(ctx context.Context, id uuid.UUID, content string) {
go func() {
vec, err := t.provider.Embed(ctx, content)
if err != nil {
t.logger.Warn("background embedding retry failed",
slog.String("thought_id", id.String()),
slog.String("error", err.Error()),
)
return
}
model := t.provider.EmbeddingModel()
if err := t.store.UpsertEmbedding(ctx, id, model, vec); err != nil {
t.logger.Warn("background embedding upsert failed",
slog.String("thought_id", id.String()),
slog.String("error", err.Error()),
)
return
}
t.logger.Info("background embedding retry succeeded", slog.String("thought_id", id.String()))
}()
}
func (t *BackfillTool) Handle(ctx context.Context, req *mcp.CallToolRequest, in BackfillInput) (*mcp.CallToolResult, BackfillOutput, error) {
limit := in.Limit
if limit <= 0 {