vxcontrol/pentagi · error
knowledge: similarity search (user %d): %w
Error message
knowledge: similarity search (user %d): %w
What it means
The user-scoped branch of doSearch runs SearchUserKnowledgeDocuments, a pgvector cosine-distance query filtered by user namespace. Any SQL execution error is wrapped as 'knowledge: similarity search (user <id>)'.
Source
Thrown at backend/pkg/database/knowledge/knowledge.go:398
type searchRow struct {
ID string
Document string
Cmetadata sql.NullString
Score float64
}
var rawRows []searchRow
if userID > 0 {
rows, err := ks.db.SearchUserKnowledgeDocuments(ctx, database.SearchUserKnowledgeDocumentsParams{
Embedding: vecLiteral,
UserID: nsOf(strconv.FormatInt(userID, 10)),
MaxDistance: maxDist,
Lim: int32(limit), //nolint:gosec
})
if err != nil {
return nil, fmt.Errorf("knowledge: similarity search (user %d): %w", userID, err)
}
rawRows = make([]searchRow, len(rows))
for i, r := range rows {
rawRows[i] = searchRow{r.ID, r.Document, r.Cmetadata, r.Score}
}
} else {
rows, err := ks.db.SearchKnowledgeDocuments(ctx, database.SearchKnowledgeDocumentsParams{
Embedding: vecLiteral,
MaxDistance: maxDist,
Lim: int32(limit), //nolint:gosec
})
if err != nil {
return nil, fmt.Errorf("knowledge: similarity search (admin): %w", err)
}
rawRows = make([]searchRow, len(rows))
for i, r := range rows {
rawRows[i] = searchRow{r.ID, r.Document, r.Cmetadata, r.Score}
}View on GitHub (pinned to ea665308ba)
Solutions
- Read the wrapped cause: 'vectors have different dimensions' means re-embed stored data or align the embedding model with the column dimension.
- Run goose migrations to create/upgrade pgvector tables and extension.
- Check PostgreSQL health and connection limits if the error is connection-related.
- Validate the limit parameter if it triggers a query error.
Example fix
// before
Lim: int32(limit), //nolint:gosec
// after
if limit <= 0 || limit > 1000 {
limit = defaultSearchLimit
}
// then: Lim: int32(limit), Defensive patterns
Strategy: validation
Validate before calling
if limit <= 0 {
limit = defaultSearchLimit
}
if strings.TrimSpace(query) == "" {
return errors.New("query must not be empty")
} Type guard
func isDimensionMismatch(err error) bool {
return strings.Contains(err.Error(), "different dimensions") || strings.Contains(err.Error(), "does not match")
} Try / catch
docs, err := store.SearchUserDocuments(ctx, userID, query, filter, limit)
if err != nil {
if isDimensionMismatch(err) {
// re-embed corpus or fix model config before retrying
}
return err
} Prevention
- Keep the embedding model fixed for the lifetime of the vector column; version vector data.
- Run pgvector migrations before deploying code that queries vectors.
- Clamp user-supplied limit values server-side.
- Monitor pgvector query latency and error rates.
When it happens
Trigger: Calling SearchUserDocuments when the vector column dimension mismatches the embedding model output, the pgvector extension is missing, limit is invalid, or the DB connection fails.
Common situations: Switching embedding models so stored vectors have a different dimension than vecLiteral (pgvector dimension mismatch error); fresh DB without migrations; connection pool exhaustion under load.
Related errors
- knowledge: similarity search (admin): %w
- failed to create flow vector store log: %w
- failed to get flow vector store log: %w
- knowledge: list by flow: %w
- knowledge: list all: %w
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/7f091934c2b4eeb9.
Report an issue: GitHub.