Python: Copy only the requested in-memory search page - #8544
Open
emme1t (emme1t) wants to merge 1 commit into
Open
emme1t (emme1t) wants to merge 1 commit into
emme1t (emme1t) wants to merge 1 commit into
Conversation
emme1t (emme1t)
had a problem deploying
to
github-app-auth
September 19, 2026 11:27 — with
GitHub Actions
Error
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused optimization preserves ordering, counts, paging, and result isolation with appropriate regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Optimizes in-memory vector search by deferring defensive copying until after paging.
Changes:
- Retains record references during scoring and sorting, then deep-copies only the selected page.
- Adds paged-search tests covering mutable-data isolation with vectors included and excluded.
| File | Description |
|---|---|
python/packages/core/agent_framework/_in_memory.py |
Moves deep-copying to the final paged result set. |
python/packages/core/tests/core/test_in_memory.py |
Verifies paging metadata, vectors, and defensive-copy behavior. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
InMemoryCollection.search()copies every matching record before selecting a result page. Small-page vector retrieval therefore allocates copies of vectors and nested data from the entire matching collection. This change limits defensive copying to the selected page.Description & Review Guide
SearchResults. Add parameterized tests for paged results with vectors included and excluded.top=3, andskip=4reduced peak search allocations from 14,696,088 to 463,508 bytes. Five untraced timing runs had medians of 3.098 seconds before and 2.046 seconds after the change on the same Windows machine. An independent rerun confirmed the same 463,508-byte peak and result semantics. These measurements apply to this workload and exclude collection setup._inner_searchand the tests covering mutable tags and vectors in a non-first result page. The scoring/sorting section contains no suspension point, and returned results receive their defensive copies before callers can consume them.The 387 related in-memory/vector tests pass, including an independent rerun. Core package lint, changed-file formatting, strict source Pyright, all five test type checkers, and applicable prek hooks pass. The core wheel and source distribution build successfully; the subsequent Poe
move-disttask requiressh, which is unavailable in this Windows environment. Full core Pyright reported 1,312 errors in the reduced dependency environment, including unresolved optional provider/MCP imports; that broader run has no baseline comparison. Full workspace and external-service integration tests were not run.Related Issue
Fixes #8543
Contribution Checklist
Prepared with Codex using Astra Ultra as part of an automated PR project contributing verified improvements to the open-source community. Implementation, tests, benchmarking, and an independent review were performed by Codex agents.