langflow-ai/langflow · error · HTTPException

Error getting chunks.

Error message

Error getting chunks.

What it means

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.

Source

Thrown at src/backend/base/langflow/api/v1/knowledge_bases.py:1658

        offset = (page - 1) * limit
        matched: list[tuple[str, str, dict[str, Any]]] = []
        matched_count = 0
        try:
            async for batch in backend.iter_documents():
                for entry in batch:
                    if not matches_filters(entry.metadata, entry.content):
                        continue
                    entry_id = (
                        entry.metadata.get("_id") or entry.metadata.get("id") or entry.metadata.get("chunk_id") or ""
                    )
                    # Only materialize entries inside the requested page; we
                    # still have to count past them for ``total_pages``.
                    if offset <= matched_count < offset + limit:
                        matched.append((entry_id, entry.content, dict(entry.metadata)))
                    matched_count += 1
        except Exception as iter_error:
            await logger.aerror("iter_documents failed for '%s': %s", kb_name, iter_error)
            raise HTTPException(status_code=500, detail="Error getting chunks.") from iter_error

        chunks = [
            ChunkInfo(id=doc_id, content=content, char_count=len(content or ""), metadata=metadata)
            for doc_id, content, metadata in matched
        ]
        return PaginatedChunkResponse(
            chunks=chunks,
            total=matched_count,
            page=page,
            limit=limit,
            total_pages=(matched_count + limit - 1) // limit if matched_count > 0 else 0,
        )

    except HTTPException:
        raise
    except Exception as e:
        await logger.aerror("Error getting chunks for '%s': %s", kb_name, e)
        raise HTTPException(status_code=500, detail="Error getting chunks.") from e

View on GitHub (pinned to 976ec789d2)

Solutions

  1. Check the server log 'iter_documents failed for <kb>: <e>' for the backend-specific cause.
  2. For Chroma KBs, ensure no other process holds the DB lock and that the KB directory was not shared between instances.
  3. Verify connectivity/credentials for remote vector-store backends.
  4. If the collection is corrupted, re-create the KB and re-ingest the source files.
Defensive patterns

Strategy: try-catch

Try / catch

try:
    resp = await client.get(f"/api/v1/knowledge_bases/{kb}/chunks", params=params)
except HTTPStatusError as e:
    if e.response.status_code == 500:
        check_server_log(f"iter_documents failed for '{kb}'")
        await verify_vector_store_health(kb)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14). Data as JSON: /api/errors/c5ad3e95687c67f6. Report an issue: GitHub.