{"record":{"id":"52b6eccb30722958","repo":"Tencent/WeKnora","slug":"invalid-retriever-type-v","errorCode":null,"errorMessage":"invalid retriever type: %v","messagePattern":"invalid retriever type: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/repository/retriever/elasticsearch/v8/repository.go","lineNumber":401,"sourceCode":"}\n\n// Retrieve dispatches the retrieval operation to the appropriate method based on retriever type\n// Returns a slice of RetrieveResult and an error if the operation fails\nfunc (e *elasticsearchRepository) Retrieve(ctx context.Context,\n\tparams typesLocal.RetrieveParams,\n) ([]*typesLocal.RetrieveResult, error) {\n\tlog := logger.GetLogger(ctx)\n\tlog.Debugf(\"[Elasticsearch] Processing retrieval request of type: %s\", params.RetrieverType)\n\n\t// Route to appropriate retrieval method\n\tswitch params.RetrieverType {\n\tcase typesLocal.VectorRetrieverType:\n\t\treturn e.VectorRetrieve(ctx, params)\n\tcase typesLocal.KeywordsRetrieverType:\n\t\treturn e.KeywordsRetrieve(ctx, params)\n\t}\n\n\terr := fmt.Errorf(\"invalid retriever type: %v\", params.RetrieverType)\n\tlog.Errorf(\"[Elasticsearch] %v\", err)\n\treturn nil, err\n}\n\n// VectorRetrieve performs vector similarity search using cosine similarity\n// Returns a slice of RetrieveResult containing matching documents\nfunc (e *elasticsearchRepository) VectorRetrieve(ctx context.Context,\n\tparams typesLocal.RetrieveParams,\n) ([]*typesLocal.RetrieveResult, error) {\n\tlog := logger.GetLogger(ctx)\n\tlog.Infof(\"[Elasticsearch] Vector retrieval: dim=%d, topK=%d, threshold=%.4f\",\n\t\tlen(params.Embedding), params.TopK, params.Threshold)\n\n\tfilter := e.getBaseConds(params)\n\n\t// Build script scoring query with cosine similarity\n\tqueryVectorJSON, err := json.Marshal(params.Embedding)\n\tif err != nil {","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/repository/retriever/elasticsearch/v8/repository.go#L383-L419","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Log the actual params.RetrieverType value returned in the error and correct it to VectorRetrieverType or KeywordsRetrieverType.","Validate/normalize the retriever type at config-load time before it reaches Retrieve.","If a new retriever type is genuinely needed, add a case in Retrieve's switch to dispatch it.","Ensure the same types package (typesLocal) is used everywhere so constants compare equal."],"exampleFix":"// before\nparams := types.RetrieveParams{RetrieverType: \"similarity\"}\nres, err := retriever.Retrieve(ctx, params)\n// after\nif params.RetrieverType != types.VectorRetrieverType && params.RetrieverType != types.KeywordsRetrieverType {\n\treturn fmt.Errorf(\"unsupported retriever type configured: %v\", params.RetrieverType)\n}\nres, err := retriever.Retrieve(ctx, params)","handlingStrategy":"validation","validationCode":"switch params.RetrieverType {\ncase types.VectorRetrieverType, types.KeywordsRetrieverType:\n\t// ok\ndefault:\n\treturn fmt.Errorf(\"unsupported retriever type: %v\", params.RetrieverType)\n}","typeGuard":"func isValidRetrieverType(t types.RetrieverType) bool {\n\treturn t == types.VectorRetrieverType || t == types.KeywordsRetrieverType\n}","tryCatchPattern":null,"preventionTips":["Validate retriever type at config-load time, before building retrieve params.","Always use the exported constants from the types package, never raw strings.","Add a default/validation case wherever retriever types are mapped from user config.","When adding a new retriever type, update every store's Retrieve switch in the same change."],"tags":["elasticsearch","go","invalid-argument","retriever"],"backgroundTag":"invalid-retriever-type","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}