Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Python: VolatileMemoryStore.get_batch and get_nearest_matches ignore with_embeddings=False (deepcopy result is discarded)

Đang mở Phù hợp với người mới
#14,522 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

@VANDRANKI đang làm issue này rồi.

Từ ngày 1/10/2026.

  • #14524 của @VANDRANKI — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
84/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu trong python/semantic_kernel/memory/volatile_memory_store.py bằng cách so sánh get_batch và get_nearest_matches với phần triển khai get đang hoạt động. Chạy bản tái hiện được cung cấp để quan sát các embedding được trả về và được lưu trữ, sau đó thêm các kiểm thử tập trung cho cả hai phương thức. Hoàn tất khi các bản sao được trả về bỏ qua embedding khi with_embeddings là false, trong khi các bản ghi được lưu trữ vẫn giữ chúng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

python triage

What happens

VolatileMemoryStore.get_batch and get_nearest_matches take a flag (with_embeddings) that is documented as "Whether to include the embeddings in the results". With the flag False (the default) the embeddings are still returned. The code makes a deepcopy and clears the embedding on the copy, but the loop variable is rebound and the copy is thrown away, so the original records are returned unchanged.

get (the single-record version) does this correctly, which shows the intended behavior.

Where

python/semantic_kernel/memory/volatile_memory_store.py on current main.

get_batch:

        if not with_embeddings:
            # create copy of results without embeddings
            for result in results:
                result = deepcopy(result)
                result._embedding = None
        return results

get_nearest_matches:

        if not with_embeddings:
            # create copy of results without embeddings
            for result in top_results:
                result = deepcopy(result)
                result[0]._embedding = None
        return top_results

In the second case deepcopy(result) copies the (record, score) tuple, and the copy is dropped. Note that a naive fix of removing the deepcopy would clear the embedding on the stored record itself, so the fix has to return copies.

Reproduce

import asyncio, numpy as np
from semantic_kernel.memory.volatile_memory_store import VolatileMemoryStore
from semantic_kernel.memory.memory_record import MemoryRecord

async def main():
    s = VolatileMemoryStore()
    await s.create_collection("c")
    await s.upsert("c", MemoryRecord.local_record("id1", "text", "desc", None, np.array([1.0, 0.0])))
    ms = await s.get_nearest_matches("c", np.array([1.0, 0.0]), limit=1)
    print("get_nearest_matches:", ms[0][0]._embedding)
    b = await s.get_batch("c", ["id1"])
    print("get_batch:", b[0]._embedding)
    g = await s.get("c", "id1")
    print("get:", g._embedding)

asyncio.run(main())

Output on semantic-kernel main (also 1.44.1):

get_nearest_matches: [1. 0.]
get_batch: [1. 0.]
get: None

Expected

All three return None for the embedding when the embeddings flag is False, and the stored records keep their embeddings. I am happy to send a fix with tests.

Ngôn ngữ chính
C#
Star
28.7k
Fork
4.8k
Merge trung bình
2 ngày 12 giờ
Pull request đã merge (30 ngày)
22

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/semantic-kernel

Tất cả issue của microsoft/semantic-kernel

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.