{"record":{"id":"50cfae61685f083d","repo":"vxcontrol/pentagi","slug":"knowledge-compute-embedding-w","errorCode":null,"errorMessage":"knowledge: compute embedding: %w","messagePattern":"knowledge: compute embedding: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/database/knowledge/knowledge.go","lineNumber":497,"sourceCode":"\tif input.AnswerType != nil {\n\t\tmeta.AnswerType = string(*input.AnswerType)\n\t}\n\tif input.CodeLang != nil {\n\t\tmeta.CodeLang = *input.CodeLang\n\t}\n\n\tcontent := strings.TrimSpace(input.Content)\n\tmeta.PartSize = len(content)\n\tmeta.TotalSize = len(content)\n\n\t// Truncate to embedding size limit for vector computation; full content goes to DB.\n\tembeddingText := content\n\tif len(embeddingText) > ks.maxEmbeddingBytes {\n\t\tembeddingText = embeddingText[:ks.maxEmbeddingBytes]\n\t}\n\tvecs, err := ks.embedder.EmbedDocuments(ctx, []string{embeddingText})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"knowledge: compute embedding: %w\", err)\n\t}\n\tif len(vecs) == 0 {\n\t\treturn nil, fmt.Errorf(\"knowledge: embedder returned no vectors\")\n\t}\n\n\tcmJSON, err := metaToJSON(meta)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"knowledge: marshal cmetadata: %w\", err)\n\t}\n\n\tid := uuid.New()\n\tdocID, err := ks.db.InsertKnowledgeDocument(ctx, database.InsertKnowledgeDocumentParams{\n\t\tUuid:      id,\n\t\tDocument:  nsOf(content),\n\t\tEmbedding: formatVector(vecs[0]),\n\t\tCmetadata: cmJSON.RawMessage,\n\t})\n\tif err != nil {","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/database/knowledge/knowledge.go#L479-L515","documentation":"CreateDocument computes an embedding for the new document content (truncated to maxEmbeddingBytes) before insertion. Failure of embedder.EmbedDocuments — nil embedder, provider auth/network errors — is wrapped as 'knowledge: compute embedding'.","triggerScenarios":"CreateDocument called when no embedding provider is configured, the provider API key is wrong/expired, the endpoint is unreachable, or the request is rate-limited.","commonSituations":"Deploying without embedding env vars (nil embedder by design); Ollama not running in the compose network; provider outage or 429 under bulk document creation.","solutions":["If the wrapped error says the embedder is not configured, set the embedding provider env vars and restart.","Validate provider credentials with a direct API call to the embeddings endpoint.","Check network reachability from the backend to the provider (DNS, proxy, ollama service name).","For 429/timeout causes, retry with backoff; for bulk imports, throttle creation rate."],"exampleFix":"// before\nvecs, err := ks.embedder.EmbedDocuments(ctx, []string{embeddingText})\n// after\nif ks.embedder == nil {\n    return nil, fmt.Errorf(\"knowledge: embedding provider not configured; set embedding env vars\")\n}\nvecs, err := ks.embedder.EmbedDocuments(ctx, []string{embeddingText})","handlingStrategy":"validation","validationCode":"if embedder == nil {\n    return errors.New(\"embedding provider not configured\")\n}\nif strings.TrimSpace(content) == \"\" {\n    return errors.New(\"document content must not be empty\")\n}\nif len(content) > maxEmbeddingBytes*100 { // absurd input guard\n    return errors.New(\"document content too large\")\n}","typeGuard":"func isEmbedderConfigErr(err error) bool {\n    return strings.Contains(err.Error(), \"not configured\")\n}","tryCatchPattern":"doc, err := store.CreateDocument(ctx, userID, input)\nif err != nil {\n    if strings.Contains(err.Error(), \"compute embedding\") {\n        // check provider status/key before surfacing to user\n        return fmt.Errorf(\"document indexing temporarily unavailable: %w\", err)\n    }\n    return err\n}","preventionTips":["Configure at least one embedding provider in every environment.","Check provider quota/limits before bulk document imports.","Truncate content to maxEmbeddingBytes client-side to keep costs predictable.","Alert on embedding API error rates."],"tags":["embeddings","network","configuration"],"backgroundTag":"embedding-provider-failure","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}