Tencent/WeKnora · error
create memory item: %w
Error message
create memory item: %w
What it means
Wraps a failure from repo.CreateItem when persisting a new or superseding memory item. The service constructed the stored item (including default Origin) but the storage layer refused or failed the insert. The write cannot complete, so no memory is recorded.
Source
Thrown at internal/application/service/memory/service.go:396
TenantID: scope.TenantID,
SubjectID: scope.SubjectID,
Kind: item.Kind,
Content: content,
Topic: topic,
NormalizedKey: normalizedKey,
Importance: types.ClampMemoryImportance(item.Importance),
Origin: item.Origin,
Status: statusForWrite(item),
SourceSessionID: item.SourceSessionID,
SourceMessageID: item.SourceMessageID,
ValidFrom: time.Now(),
ExpiresAt: item.ExpiresAt,
}
if stored.Origin == "" {
stored.Origin = types.MemoryOriginExtracted
}
if err := s.repo.CreateItem(ctx, stored); err != nil {
return nil, fmt.Errorf("create memory item: %w", err)
}
if existing != nil {
// Supersede rather than delete: the old statement keeps its content
// and gains invalid_at, so the memory manager can show what changed.
if err := s.repo.SupersedeItem(ctx, scope, existing.ID, stored.ID); err != nil {
logger.Warnf(ctx, "memory: supersede %s failed: %v", existing.ID, err)
}
}
s.enforceCapacity(ctx, scope, cfg)
s.rebuildBlock(ctx, scope)
// A memory with no vector is invisible to semantic recall, so this runs on
// every write. It is best effort: failing to embed must not fail the write,
// and the backfill pass picks up whatever this missed.
s.storeItemEmbedding(ctx, scope, cfg, stored)
return stored, nil
}
View on GitHub (pinned to 988cbb0330)
Solutions
- Inspect the wrapped error for the concrete DB failure (constraint, size, connection) and address it.
- Verify item ID generation and unique indexes to rule out key collisions.
- Check content/topic sanitization and length limits against the schema.
- Retry after transient DB errors; supersede logic preserves history so a retry is safe.
Example fix
// before
if err := s.repo.CreateItem(ctx, stored); err != nil {
return nil, fmt.Errorf("create memory item: %w", err)
}
// after
if err := s.repo.CreateItem(ctx, stored); err != nil {
if ctx.Err() != nil {
return nil, fmt.Errorf("create memory item: %w", ctx.Err())
}
return nil, fmt.Errorf("create memory item: %w", err)
} Defensive patterns
Strategy: retry
Validate before calling
// pre-validate before calling write
if len(item.Content) > maxContentLen { return fmt.Errorf("content too long: %d", len(item.Content)) }
if strings.TrimSpace(item.Topic) == "" { return fmt.Errorf("topic required") } Try / catch
stored, err := svc.Remember(ctx, scope, item)
if err != nil && strings.Contains(err.Error(), "create memory item") {
if isTransient(err) { stored, err = svc.Remember(ctx, scope, item) } // idempotent retry
} Prevention
- Keep content within DB column limits
- Ensure unique index matches your ID generation to avoid collisions
- Retry idempotently — identical content returns the existing item
When it happens
Trigger: Any of write/Remember/PromoteTopic/CreateItem/mergeRedundant/applyDecisions/observeTopics reaching repo.CreateItem and the insert failing — DB down, unique constraint conflict on item key, invalid column value (e.g. oversized content), or context cancellation.
Common situations: Duplicate ID collision when generating item IDs; content exceeding a DB column limit; database read-only or disk full in self-hosted deployments; context canceled because the HTTP request timed out mid-write.
Related errors
- check forgotten memory: %w
- check forgotten source: %w
- ensure memory subject: %w
- find conflicting memory: %w
- scan for duplicate memory: %w
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/299058032ba7afd7.
Report an issue: GitHub.