#8822·langgraph

InMemoryStore.batch() raises ValueError when multiple items contain identical indexed text

Author: yang0228Created Sep 4, 2026Updated Sep 29, 2026
Labelsbugexternal

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

python
from collections.abc import Sequence

from langgraph.store.base import PutOp
from langgraph.store.memory import InMemoryStore


def embed(texts: Sequence[str]) -> list[list[float]]:
    print(f"embed() received {len(texts)} unique text(s): {list(texts)!r}", flush=True)
    return [[float(len(text)), 1.0] for text in texts]


store = InMemoryStore(
    index={"dims": 2, "embed": embed, "fields": ["text"]},
)
operations = [
    PutOp(("docs",), "doc-a", {"text": "same text"}),
    PutOp(("docs",), "doc-b", {"text": "same text"}),
]

print(f"PutOp count: {len(operations)}", flush=True)
print("Both operations index the identical value: 'same text'", flush=True)
print("Calling InMemoryStore.batch(...)", flush=True)
store.batch(operations)

Error Message and Stack Trace (if applicable)

bash
PutOp count: 2
Both operations index the identical value: 'same text'
Calling InMemoryStore.batch(...)
embed() received 1 unique text(s): ['same text']
Traceback (most recent call last):
  File "repro_inmemory_duplicate_texts.py", line 26, in <module>
    store.batch(operations)
  File "libs/checkpoint/langgraph/store/memory/__init__.py", line 217, in batch
    self._insertinmem_store(to_embed, embeddings)
  File "libs/checkpoint/langgraph/store/memory/__init__.py", line 453, in _insertinmem_store
    raise ValueError(
ValueError: Number of embeddings (1) does not match number of indices (2)

Description

I am batching two PutOp instances with different keys whose configured index field contains the same text.

Expected behavior

InMemoryStore should embed the unique text once and reuse that embedding for both index targets. Both items should be stored successfully and remain available for vector search.

Actual behavior

The embedding function receives one deduplicated text, but _insertinmem_store() expects one embedding per flattened index target. It compares one embedding with two indices and raises ValueError before applying either put operation. The same failure occurs through abatch().

Root cause

_extract_texts() maps each unique text to all of its index targets. batch() and abatch() correctly produce one embedding per unique text, but _insertinmem_store() flattens the target lists and assumes embeddings and targets are one-to-one. That assumption fails whenever a text maps to multiple targets.

Suggested fix

Keep the existing text deduplication, associate each returned embedding with its unique-text entry, and write it to every target in that entry. Validate the number of embeddings against the number of unique texts rather than the flattened number of targets. Sync and async regression tests should cover identical indexed text across distinct keys in one batch.

@mdrxy, could you please confirm whether this bug and the proposed fix direction look valid? If so, would you please assign this issue to me? I'd be happy to submit a PR with sync and async regression tests after approval.

System Info

Reproduced with langgraph-checkpoint==4.2.0 and current main at 81bf17b23123e4ef8b9d5f49fa09a0122fc2edd1.

System Information

OS: Darwin OS Version: Darwin Kernel Version 25.6.0: Fri Jul 31 19:16:20 PDT 2026; root:xnu-12377.161.14~5/RELEASE_ARM64_T8142 Python Version: 3.14.6 (main, Jun 23 2026, 15:46:31) [Clang 22.1.3]

Package Information

langgraph-checkpoint: 4.2.0 (editable source checkout) langchain_core: 1.6.1 langsmith: 0.8.18 langchain_protocol: 0.0.18

Other Dependencies

httpx: 0.28.1 jsonpatch: 1.33 orjson: 3.11.6 packaging: 25.0 pydantic: 2.12.5 pytest: 9.1.1 pyyaml: 6.0.3 requests: 2.33.0 requests-toolbelt: 1.0.0 tenacity: 9.1.2 typing-extensions: 4.15.0 uuid-utils: 0.13.0 websockets: 16.0 xxhash: 3.6.0 zstandard: 0.25.0