Tencent/WeKnora · error

invalid retriever type: %v

Error message

invalid retriever type: %v

What it means

Retrieve dispatches to the retriever implementation matching params.RetrieverType (vector or keywords). When the requested type matches no known VectorRetrieverType/KeywordsRetrieverType value, it returns 'invalid retriever type: %v' naming the offending value. This is a caller input/validation error, not an infrastructure failure.

Source

Thrown at internal/application/repository/retriever/elasticsearch/v8/repository.go:401

}

// Retrieve dispatches the retrieval operation to the appropriate method based on retriever type
// Returns a slice of RetrieveResult and an error if the operation fails
func (e *elasticsearchRepository) Retrieve(ctx context.Context,
	params typesLocal.RetrieveParams,
) ([]*typesLocal.RetrieveResult, error) {
	log := logger.GetLogger(ctx)
	log.Debugf("[Elasticsearch] Processing retrieval request of type: %s", params.RetrieverType)

	// Route to appropriate retrieval method
	switch params.RetrieverType {
	case typesLocal.VectorRetrieverType:
		return e.VectorRetrieve(ctx, params)
	case typesLocal.KeywordsRetrieverType:
		return e.KeywordsRetrieve(ctx, params)
	}

	err := fmt.Errorf("invalid retriever type: %v", params.RetrieverType)
	log.Errorf("[Elasticsearch] %v", err)
	return nil, err
}

// VectorRetrieve performs vector similarity search using cosine similarity
// Returns a slice of RetrieveResult containing matching documents
func (e *elasticsearchRepository) VectorRetrieve(ctx context.Context,
	params typesLocal.RetrieveParams,
) ([]*typesLocal.RetrieveResult, error) {
	log := logger.GetLogger(ctx)
	log.Infof("[Elasticsearch] Vector retrieval: dim=%d, topK=%d, threshold=%.4f",
		len(params.Embedding), params.TopK, params.Threshold)

	filter := e.getBaseConds(params)

	// Build script scoring query with cosine similarity
	queryVectorJSON, err := json.Marshal(params.Embedding)
	if err != nil {

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Log the actual params.RetrieverType value returned in the error and correct it to VectorRetrieverType or KeywordsRetrieverType.
  2. Validate/normalize the retriever type at config-load time before it reaches Retrieve.
  3. If a new retriever type is genuinely needed, add a case in Retrieve's switch to dispatch it.
  4. Ensure the same types package (typesLocal) is used everywhere so constants compare equal.

Example fix

// before
params := types.RetrieveParams{RetrieverType: "similarity"}
res, err := retriever.Retrieve(ctx, params)
// after
if params.RetrieverType != types.VectorRetrieverType && params.RetrieverType != types.KeywordsRetrieverType {
	return fmt.Errorf("unsupported retriever type configured: %v", params.RetrieverType)
}
res, err := retriever.Retrieve(ctx, params)
Defensive patterns

Strategy: validation

Validate before calling

switch params.RetrieverType {
case types.VectorRetrieverType, types.KeywordsRetrieverType:
	// ok
default:
	return fmt.Errorf("unsupported retriever type: %v", params.RetrieverType)
}

Type guard

func isValidRetrieverType(t types.RetrieverType) bool {
	return t == types.VectorRetrieverType || t == types.KeywordsRetrieverType
}

Prevention

When it happens

Trigger: Calling Retrieve with params.RetrieverType set to an unsupported value — e.g. zero-value/empty string, a typo, a raw string cast, or a retriever type added in a newer version of the types package that this elasticsearch/v8 repository does not implement yet.

Common situations: Config-driven retriever selection where the config value ('hybrid', 'fulltext', '') is passed through unvalidated; enum renamed after refactor so old persisted values no longer match; mixing retriever type constants from a different types package.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/52b6eccb30722958. Report an issue: GitHub.