{"record":{"id":"6179685602bfee16","repo":"vxcontrol/pentagi","slug":"failed-to-load-document-w-617968","errorCode":null,"errorMessage":"failed to load document: %w","messagePattern":"failed to load document: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/search.go","lineNumber":278,"sourceCode":"\t\t\tmetadata[\"subtask_id\"] = *s.subtaskID\n\t\t}\n\n\t\tvar (\n\t\t\tdocs []schema.Document\n\t\t\tids  []string\n\t\t\terr  error\n\t\t)\n\n\t\tif len(anonymizedAnswer) <= s.maxEmbeddingBytes || s.embedder == nil {\n\t\t\t// Fast path: answer fits within the embedding limit.\n\t\t\tdocs, err = documentloaders.NewText(strings.NewReader(anonymizedAnswer)).Load(ctx)\n\t\t\tif err != nil {\n\t\t\t\tobservation.Event(append(opts,\n\t\t\t\t\tlangfuse.WithEventStatus(err.Error()),\n\t\t\t\t\tlangfuse.WithEventLevel(langfuse.ObservationLevelError),\n\t\t\t\t)...)\n\t\t\t\tlogger.WithError(err).Error(\"failed to load document\")\n\t\t\t\treturn \"\", fmt.Errorf(\"failed to load document: %w\", err)\n\t\t\t}\n\t\t\tfor i := range docs {\n\t\t\t\tif docs[i].Metadata == nil {\n\t\t\t\t\tdocs[i].Metadata = map[string]any{}\n\t\t\t\t}\n\t\t\t\tmaps.Copy(docs[i].Metadata, metadata)\n\t\t\t\tdocs[i].Metadata[\"part_size\"] = len(docs[i].PageContent)\n\t\t\t}\n\t\t\tids, err = s.store.AddDocuments(ctx, docs)\n\t\t\teventMetadata[\"ids\"] = ids\n\t\t\tif err != nil {\n\t\t\t\tobservation.Event(append(opts,\n\t\t\t\t\tlangfuse.WithEventStatus(err.Error()),\n\t\t\t\t\tlangfuse.WithEventLevel(langfuse.ObservationLevelError),\n\t\t\t\t)...)\n\t\t\t\tlogger.WithError(err).Error(\"failed to store answer for question\")\n\t\t\t\treturn \"\", fmt.Errorf(\"failed to store answer for question: %w\", err)\n\t\t\t}","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/search.go#L260-L296","documentation":"The vector store failed to load documents for the store-answer flow — i.e. the embedding/retrieval backend (pgvector) returned an error while `s.store.Load(ctx, ...)` ran, after the answer was anonymized and the document was built. The underlying DB/embedding error is wrapped for diagnosis.","triggerScenarios":"During `StoreAnswerToolName` handling, the call that loads/stores the document into pgvector returns an error — DB connection failure, pgvector extension missing, embedding provider error, dimension mismatch, or context canceled/deadline exceeded.","commonSituations":"Postgres restarted or connection pool exhausted; pgvector index missing after migration failure; embedding model changed so vector dimensions no longer match the column; long answers causing embedding timeouts.","solutions":["Check the wrapped `%w` error and backend logs for the root cause (DB vs embedding).","Verify Postgres/pgvector availability and run pending migrations.","Confirm the embedding model's dimensions match the vector column definition.","Retry with a fresh context if the cause was a deadline/cancellation.","Check Langfuse event status recorded alongside the error for the upstream message."],"exampleFix":"// before\nctx := context.Background() // unbounded; timeouts kill long embeddings\n// after\nctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\ndefer cancel()","handlingStrategy":"try-catch","validationCode":"if err := pgPing(ctx, dsn); err != nil {\n    return fmt.Errorf(\"pgvector unreachable before store answer: %w\", err)\n}\nif embDim := embeddingDims(ctx, model); embDim != expectedDim {\n    return fmt.Errorf(\"embedding dims %d != column dims %d\", embDim, expectedDim)\n}","typeGuard":null,"tryCatchPattern":"out, err := searchTool.Handle(ctx, tools.StoreAnswerToolName, args)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to load document\") {\n        if isTransientDBError(errors.Unwrap(err)) {\n            return retryWithBackoff(ctx, 3, func() error { return storeAnswer(ctx, args) })\n        }\n        return fmt.Errorf(\"vector store unavailable, answer not saved: %w\", err)\n    }\n    return err\n}","preventionTips":["Health-check Postgres/pgvector before flow start and during flows.","Keep embedding model and vector column dimensions in lockstep; migrate on model change.","Set generous but bounded context timeouts for embedding+write operations.","Verify migrations ran (pgvector extension + indexes) at deploy time."],"tags":["pgvector","embedding","document-load","database"],"backgroundTag":"vector-store-load-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}