{"record":{"id":"c5ad3e95687c67f6","repo":"langflow-ai/langflow","slug":"error-getting-chunks","errorCode":null,"errorMessage":"Error getting chunks.","messagePattern":"Error getting chunks\\.","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/backend/base/langflow/api/v1/knowledge_bases.py","lineNumber":1658,"sourceCode":"        offset = (page - 1) * limit\n        matched: list[tuple[str, str, dict[str, Any]]] = []\n        matched_count = 0\n        try:\n            async for batch in backend.iter_documents():\n                for entry in batch:\n                    if not matches_filters(entry.metadata, entry.content):\n                        continue\n                    entry_id = (\n                        entry.metadata.get(\"_id\") or entry.metadata.get(\"id\") or entry.metadata.get(\"chunk_id\") or \"\"\n                    )\n                    # Only materialize entries inside the requested page; we\n                    # still have to count past them for ``total_pages``.\n                    if offset <= matched_count < offset + limit:\n                        matched.append((entry_id, entry.content, dict(entry.metadata)))\n                    matched_count += 1\n        except Exception as iter_error:\n            await logger.aerror(\"iter_documents failed for '%s': %s\", kb_name, iter_error)\n            raise HTTPException(status_code=500, detail=\"Error getting chunks.\") from iter_error\n\n        chunks = [\n            ChunkInfo(id=doc_id, content=content, char_count=len(content or \"\"), metadata=metadata)\n            for doc_id, content, metadata in matched\n        ]\n        return PaginatedChunkResponse(\n            chunks=chunks,\n            total=matched_count,\n            page=page,\n            limit=limit,\n            total_pages=(matched_count + limit - 1) // limit if matched_count > 0 else 0,\n        )\n\n    except HTTPException:\n        raise\n    except Exception as e:\n        await logger.aerror(\"Error getting chunks for '%s': %s\", kb_name, e)\n        raise HTTPException(status_code=500, detail=\"Error getting chunks.\") from e","sourceCodeStart":1640,"sourceCodeEnd":1676,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/knowledge_bases.py#L1640-L1676","documentation":"A 500 raised specifically when iterating a KB's documents fails while paginating chunks: the vector-store backend's iter_documents() raised, the handler logs 'iter_documents failed for <kb>' and converts it to 'Error getting chunks.' Pagination, search substring filtering, and source_type filtering happen during iteration, so backend-side read errors surface here.","triggerScenarios":"GET /api/v1/knowledge_bases/{kb_name}/chunks when the underlying vector store (Chroma/other backend) raises while streaming documents — corrupted collection, lock contention, connection loss for remote backends, or schema mismatch between recorded backend type and actual store contents.","commonSituations":"Chroma collections corrupted by concurrent access or unclean shutdown; remote backends (Astra/Mongo/Postgres) unreachable; a KB directory reused across backend types after config changes.","solutions":["Check the server log 'iter_documents failed for <kb>: <e>' for the backend-specific cause.","For Chroma KBs, ensure no other process holds the DB lock and that the KB directory was not shared between instances.","Verify connectivity/credentials for remote vector-store backends.","If the collection is corrupted, re-create the KB and re-ingest the source files."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = await client.get(f\"/api/v1/knowledge_bases/{kb}/chunks\", params=params)\nexcept HTTPStatusError as e:\n    if e.response.status_code == 500:\n        check_server_log(f\"iter_documents failed for '{kb}'\")\n        await verify_vector_store_health(kb)","preventionTips":["Avoid concurrent processes opening the same Chroma KB directory.","Keep remote vector-store credentials and connectivity verified.","Treat chunk-read 500s as store health signals; pause ingestion rather than retrying blindly."],"tags":["knowledge-base","chunks","vector-store","http-500"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}