agentscope-ai/agentscope · error · RuntimeError

Elasticsearch bulk insert failed for {len(failures)} record(

Error message

Elasticsearch bulk insert failed for {len(failures)} record(s)

What it means

After a bulk _bulk API call, Elasticsearch reported partial errors; the store counts failing items and raises RuntimeError, aborting the insert even if some records succeeded.

Source

Thrown at src/agentscope/rag/_vdb/_elasticsearch.py:157

                        "vector": record.vector,
                        "document_id": record.document_id,
                        "chunk": record.chunk.model_dump(mode="json"),
                        "metadata": record.chunk.metadata,
                    },
                ],
            )

        response = await self.get_client().bulk(
            operations=operations,
            refresh=self._refresh,
        )
        if response.get("errors"):
            failures = [
                item
                for item in response.get("items", [])
                if next(iter(item.values())).get("error")
            ]
            raise RuntimeError(
                f"Elasticsearch bulk insert failed for {len(failures)} "
                "record(s)",
            )

    async def delete(self, collection: str, document_id: str) -> None:
        """Delete every chunk belonging to one source document."""
        await self.get_client().delete_by_query(
            index=collection,
            query={"term": {"document_id": document_id}},
            conflicts="proceed",
            refresh=self._refresh is not False,
        )

    async def search(
        self,
        collection: str,
        query_vector: list[float],
        top_k: int = 5,

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Check the ES logs / rerun with response inspection to see item['index']['error'] reasons
  2. Verify vector dimension matches the index mapping; recreate collection if the embedding model changed
  3. Reduce batch size if payloads exceed limits
  4. Free disk space / resolve cluster watermark issues

Example fix

# before
vdb = ElasticsearchVectorDatabase(..., dim=384)
vdb.insert(collection, records_768_dim)
# after
vdb = ElasticsearchVectorDatabase(..., dim=768)
vdb.insert(collection, records_768_dim)
Defensive patterns

Strategy: try-catch

Validate before calling

assert all(len(r['vector']) == expected_dim for r in records)

Type guard

def dims_match(records, dim: int) -> bool:
    return all(len(r['vector']) == dim for r in records)

Try / catch

try:
    await vdb.insert(coll, records)
except RuntimeError as e:
    if 'bulk insert failed' in str(e):
        logger.error('partial bulk failure; check item errors and index mapping')
    raise

Prevention

When it happens

Trigger: insert() with malformed records (bad vector dimension vs index mapping), oversized payloads, or cluster issues (disk watermark exceeded, mapper parsing exceptions) causing per-item errors in the bulk response.

Common situations: Embedding model changed so vectors no longer match the index dimension; indexing after switching embedding providers without recreating the collection.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/73aea1e28ab986d0. Report an issue: GitHub.