{"record":{"id":"ec273fbb54d631f1","repo":"Tencent/WeKnora","slug":"chunk-query-returned-no-data","errorCode":null,"errorMessage":"chunk query returned no data","messagePattern":"chunk query returned no data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/list_knowledge_chunks.go","lineNumber":161,"sourceCode":"\tpagination := &types.Pagination{\n\t\tPage:     offset/chunkLimit + 1,\n\t\tPageSize: chunkLimit,\n\t}\n\n\tenabled := true\n\tchunks, total, err := t.chunkService.GetRepository().ListPagedChunksByKnowledgeID(ctx,\n\t\teffectiveTenantID, knowledgeID, pagination, []types.ChunkType{types.ChunkTypeText, types.ChunkTypeFAQ}, nil, \"\", \"\", \"\", \"\", &enabled)\n\tif err != nil {\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError:   fmt.Sprintf(\"failed to list chunks: %v\", err),\n\t\t}, err\n\t}\n\tif chunks == nil {\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError:   \"chunk query returned no data\",\n\t\t}, fmt.Errorf(\"chunk query returned no data\")\n\t}\n\n\ttotalChunks := total\n\tfetched := len(chunks)\n\n\t// Explicit out-of-range guidance: when the caller paged past the end\n\t// (offset >= total with total > 0), silently returning fetched=0 is\n\t// confusing for LLMs that just saw the document in search results. Tell\n\t// them exactly what happened and what offset would be valid so the next\n\t// call lands on a real page.\n\tif fetched == 0 && totalChunks > 0 && int64(offset) >= totalChunks {\n\t\tsuggestedOffset := totalChunks - int64(chunkLimit)\n\t\tif suggestedOffset < 0 {\n\t\t\tsuggestedOffset = 0\n\t\t}\n\t\treturn &types.ToolResult{\n\t\t\tSuccess: false,\n\t\t\tError: fmt.Sprintf(","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/list_knowledge_chunks.go#L143-L179","documentation":"After authorize and chunk query succeed, if the chunk query returns a nil chunks slice the tool treats it as an abnormal empty result and fails with this error rather than rendering an empty page. It signals the data layer returned no data object at all for the requested knowledge item.","triggerScenarios":"Calling list_knowledge_chunks against a knowledge item whose chunk storage returned nil — e.g. knowledge exists but has never been indexed/chunked, or a backend inconsistency where total is unset and chunks is nil.","commonSituations":"Querying a freshly created FAQ/knowledge entry before ingestion completed; document ingestion pipeline failed silently; querying the wrong environment/database with sparse data.","solutions":["Verify the knowledge item has completed ingestion (has chunks) before paging it","Re-run or trigger the ingestion/indexing pipeline for the item","Check backend storage connectivity/consistency for the knowledge service","Handle it as 'no chunks exist yet' in the caller if empty results are acceptable"],"exampleFix":"// before\nres, err := listChunks.Execute(ctx, {\"knowledge_id\": \"kb-9\"}) // kb-9 not yet indexed\n// after\nstatus := knowledgeService.GetIngestionStatus(ctx, \"kb-9\")\nif status.Completed { res, err = listChunks.Execute(ctx, {\"knowledge_id\": \"kb-9\"}) }","handlingStrategy":"validation","validationCode":"status, err := knowledgeService.GetIngestionStatus(ctx, knowledgeID)\nif err != nil || !status.Indexed {\n    return fmt.Errorf(\"knowledge %s not indexed yet\", knowledgeID)\n}","typeGuard":null,"tryCatchPattern":"res, err := tool.Execute(ctx, input)\nif err != nil && strings.Contains(err.Error(), \"chunk query returned no data\") {\n    log.Printf(\"knowledge item has no chunks — check ingestion pipeline\")\n    return emptyPageResult(), nil // treat as empty if acceptable\n}","preventionTips":["Ensure ingestion/indexing completes before listing chunks","Monitor the ingestion pipeline for silent failures","Verify you are querying the intended environment/database","Handle empty chunk sets gracefully in UIs"],"tags":["go","agent-tools","knowledge-chunks","empty-result","data-layer"],"backgroundTag":"query-returned-no-data","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}