{"record":{"id":"d4c85d538e152285","repo":"vxcontrol/pentagi","slug":"pgvector-store-is-not-initialized-d4c85d","errorCode":null,"errorMessage":"pgvector store is not initialized","messagePattern":"pgvector store is not initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/search.go","lineNumber":81,"sourceCode":"\t\tstore:             store,\n\t\tembedder:          embedder,\n\t\tdb:                db,\n\t\tmaxEmbeddingBytes: maxEmbeddingBytes,\n\t\tvslp:              vslp,\n\t\tknp:               knp,\n\t}\n}\n\nfunc (s *search) Handle(ctx context.Context, name string, args json.RawMessage) (string, error) {\n\tctx, observation := obs.Observer.NewObservation(ctx)\n\tlogger := logrus.WithContext(ctx).WithFields(enrichLogrusFields(s.flowID, s.taskID, s.subtaskID, logrus.Fields{\n\t\t\"tool\": name,\n\t\t\"args\": string(args),\n\t}))\n\n\tif s.store == nil {\n\t\tlogger.Error(\"pgvector store is not initialized\")\n\t\treturn \"\", fmt.Errorf(\"pgvector store is not initialized\")\n\t}\n\n\tswitch name {\n\tcase SearchAnswerToolName:\n\t\tvar action SearchAnswerAction\n\t\tif err := json.Unmarshal(args, &action); err != nil {\n\t\t\tlogger.WithError(err).Error(\"failed to unmarshal search answer action arguments\")\n\t\t\treturn \"\", fmt.Errorf(\"failed to unmarshal %s search answer action arguments: %w\", name, err)\n\t\t}\n\n\t\tfilters := map[string]any{\n\t\t\t\"doc_type\":    searchVectorStoreDefaultType,\n\t\t\t\"answer_type\": action.Type,\n\t\t}\n\n\t\tmetadata := langfuse.Metadata{\n\t\t\t\"tool_name\":     name,\n\t\t\t\"message\":       action.Message,","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/search.go#L63-L99","documentation":"The search tool's `Handle` was invoked while its pgvector-backed store field is nil, so no vector search can be performed. `IsAvailable()` returns false in this state; this error enforces that contract for direct calls that bypass the availability check.","triggerScenarios":"Calling `search.Handle(ctx, name, args)` when `NewSearch` was constructed without a vector store (pgvector unreachable at startup, disabled by config) or the store failed to initialize, instead of checking `IsAvailable()` first.","commonSituations":"Postgres/pgvector not running or wrong DSN at container start; vector-store feature disabled via env config but agent config still lists the search tools; construction error swallowed so the tool object exists with a nil store.","solutions":["Check `IsAvailable()` before invoking the tool and exclude it from the agent's toolset when false.","Verify pgvector/Postgres connectivity and DSN env config; restart the backend after fixing.","Inspect startup logs for the vector-store initialization error that left the store nil.","Fix the wiring so construction fails fast instead of registering a tool with a nil store."],"exampleFix":"// before\nout, err := searchTool.Handle(ctx, tools.SearchAnswerToolName, args)\n// after\nif !searchTool.IsAvailable() {\n    return errors.New(\"search tool unavailable: pgvector store not initialized\")\n}\nout, err := searchTool.Handle(ctx, tools.SearchAnswerToolName, args)","handlingStrategy":"type-guard","validationCode":"if !searchTool.IsAvailable() {\n    return errors.New(\"search tool unavailable: pgvector store not initialized\")\n}","typeGuard":"func usable(s *search.Search) bool {\n    return s != nil && s.IsAvailable()\n}","tryCatchPattern":"if err := handle(ctx, name, args); err != nil {\n    if strings.Contains(err.Error(), \"pgvector store is not initialized\") {\n        return fallbackKeywordSearch(ctx, args) // degrade gracefully\n    }\n    return err\n}","preventionTips":["Check IsAvailable() before adding any vector tool to the agent toolset.","Fail fast at startup if pgvector is required but unreachable.","Monitor container health for Postgres/pgvector so nil-store states are caught early."],"tags":["pgvector","initialization","availability","vector-store"],"backgroundTag":"store-not-initialized","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}