Repository navigation
Python: Fix VolatileMemoryStore.get_nearest_match returning an un-awaited coroutine - #14523
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused fix matches established implementations and is covered by targeted regression tests.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes VolatileMemoryStore.get_nearest_match to return the nearest record and score instead of an un-awaited coroutine.
Changes:
- Awaits
get_nearest_matchesand returns its first result. - Adds regression tests for tuple results and relevance thresholds.
| File | Description |
|---|---|
python/semantic_kernel/memory/volatile_memory_store.py |
Corrects asynchronous result handling. |
python/tests/unit/memory/test_volatile_memory_store.py |
Adds regression coverage for nearest-match behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
The coroutine fix and both regression tests pass in review. This PR now has merge conflicts, and the current head has no completed Python validation jobs. Please rebase onto current main and rerun CI before this can be approved and queued. |
…ction (microsoft#14536) ### Motivation and Context `VolatileMemoryStore.get_nearest_matches` raises `ValueError: cannot reshape array of size 0 into shape (0,newaxis)` when the collection exists but has no records. A search on a new or emptied collection should return no results, as it already does for a missing collection. Fixes microsoft#14534 ### Description Return `[]` early when the collection has no records, before the embeddings are stacked and reshaped. Added two tests: a freshly created collection, and a collection whose only record was removed. Both fail on `main` with the ValueError and pass with the fix. The tests are in a new file to avoid touching the files used by open PRs microsoft#14523 and microsoft#14524. Checks: ruff format and check clean, mypy clean on the changed file. ### Contribution Checklist - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
|
I tried to rebase this, but there is nothing left to rebase. The conflict comes from #14580 (merged 2026-10-28), which made the same change on main: get_nearest_match now awaits get_nearest_matches. Main also raises ServiceResourceNotFoundError("No match found") when nothing matches. My version would have raised IndexError on I ran the 2 tests from this PR against main's volatile_memory_store.py, together with main's own test file for it. All 7 passed. So the fix in this PR is already in main, and the 2 tests pass there without it. I suggest closing this PR as superseded by #14580. I have not closed it, in case you want my two fixture based tests kept. |
Motivation and Context
VolatileMemoryStore.get_nearest_matchisasync defbut returnedself.get_nearest_matches(...)without awaiting it, so callers received a coroutine instead of a(MemoryRecord, score)tuple. Fixes #14521.Description
Await
get_nearest_matchesand return its first element, the same wayChromaMemoryStore.get_nearest_matchdoes. Addedtests/unit/memory/test_volatile_memory_store.pywith two tests. Both fail on main (they receive a coroutine) and pass with the change.Contribution Checklist