Skip to content

Python: Fix VolatileMemoryStore.get_nearest_match returning an un-awaited coroutine - #14523

Open
PRABHU KIRAN VANDRANKI (VANDRANKI) wants to merge 1 commit into
microsoft:mainfrom
VANDRANKI:fix/volatile-memory-get-nearest-match
Open

PRABHU KIRAN VANDRANKI (VANDRANKI) wants to merge 1 commit into
microsoft:mainfrom
VANDRANKI:fix/volatile-memory-get-nearest-match

Conversation

@VANDRANKI

Copy link
Copy Markdown
Contributor

Motivation and Context

VolatileMemoryStore.get_nearest_match is async def but returned self.get_nearest_matches(...) without awaiting it, so callers received a coroutine instead of a (MemoryRecord, score) tuple. Fixes #14521.

Description

Await get_nearest_matches and return its first element, the same way ChromaMemoryStore.get_nearest_match does. Added tests/unit/memory/test_volatile_memory_store.py with two tests. Both fail on main (they receive a coroutine) and pass with the change.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the SK Contribution Guidelines (ruff and mypy are clean on the changed files)
  • All unit tests pass, and I have added new tests where possible
  • I didn't break anyone

Copilot AI balanced review requested due to automatic review settings October 1, 2026 16:56
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_matches and 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.

@eavanvalkenburg

Copy link
Copy Markdown
Member

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.

Anton Dziatkovskii (tonydzi) pushed a commit to tonydzi/semantic-kernel that referenced this pull request Nov 2, 2026
…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 😄

This branch was previously deployed

1 inactive deployment
github-app-auth — 169a7a03 Deployed Oct 1, 2026 by VANDRANKI via team_check #571
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: VolatileMemoryStore.get_nearest_match returns an un-awaited coroutine instead of a (MemoryRecord, score) tuple

3 participants