vxcontrol/pentagi · warning

Knowledge.InvalidRequest

Knowledge.InvalidRequest

Error message

group field not found

What it means

ListDocuments in the knowledge service supports grouped queries. If query.Group names a field not present in knowledgeSQLMappers, the service returns this Knowledge.InvalidRequest error, mirroring the same group-validation pattern used in other services, to prevent grouping on unknown columns.

Source

Thrown at backend/pkg/server/services/knowledge.go:194

			Where("langchain_pg_collection.name = ?", "langchain").
			Where("COALESCE(langchain_pg_embedding.cmetadata ->> 'doc_type', '') NOT IN (?)", []string{"memory"})
	}

	// Authorization scope: admins see all documents; regular users see only their own.
	authScope := func(db *gorm.DB) *gorm.DB {
		if admin {
			return db
		}
		return db.Where("(langchain_pg_embedding.cmetadata ->> 'user_id')::bigint = ?", uid)
	}

	// ---- Grouped query -------------------------------------------------------
	// When a group field is requested the response is a list of distinct values
	// rather than full document rows (mirrors the pattern used in other services).
	if query.Group != "" {
		if _, ok := knowledgeSQLMappers[query.Group]; !ok {
			logger.FromContext(c).Errorf("group field %q not found in knowledge mappers", query.Group)
			response.Error(c, response.ErrKnowledgeInvalidRequest, errors.New("group field not found"))
			return
		}

		var resp knowledgeGrouped
		var err error
		if resp.Total, err = query.QueryGrouped(s.db, &resp.Grouped, baseScope, authScope); err != nil {
			logger.FromContext(c).WithError(err).Error("error querying knowledge documents grouped")
			response.Error(c, response.ErrInternal, err)
			return
		}

		response.Success(c, http.StatusOK, resp)
		return
	}

	// ---- Paginated / sorted query --------------------------------------------

	// Override the default "ORDER BY id DESC" — the PK column is uuid, not id.

View on GitHub (pinned to ea665308ba)

Solutions

  1. Use a field that exists in knowledgeSQLMappers (inspect pkg/server/services/knowledge.go).
  2. Align the group parameter with the current knowledge schema field names.
  3. If grouping was copied from another endpoint, verify each service has its own mapper set.
  4. Add the field to knowledgeSQLMappers if grouping by it is a legitimate new requirement.

Example fix

// before
GET /knowledge/documents?group=documentType
// after
GET /knowledge/documents?group=document_type
Defensive patterns

Strategy: validation

Validate before calling

const KNOWLEDGE_GROUPS = ['document_type','status','created_at']; // mirror knowledgeSQLMappers
if (group && !KNOWLEDGE_GROUPS.includes(group)) {
  throw new Error(`group field not found: ${group}`);
}

Try / catch

try {
  const docs = await listKnowledgeDocuments({ group });
  render(docs);
} catch (e) {
  if (e.code === 'Knowledge.InvalidRequest' && /group field not found/.test(e.message)) {
    clearGrouping();
    notify('This field cannot be used for grouping documents.');
  } else { throw e; }
}

Prevention

When it happens

Trigger: GET knowledge documents list with ?group=<field> where <field> is not a key of knowledgeSQLMappers (typo, renamed column, or non-groupable field).

Common situations: Client-side faceted-search UI emitting stale field names after a schema change; copy-pasted group param from another service (flows/msglogs) whose mappers differ; camelCase vs snake_case mismatch.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/86622a73af95d9bc. Report an issue: GitHub.