Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

确保在 index 范围之内 #1980

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chromadb/api/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def _get(

return GetResult(
ids=[r["id"] for r in records],
embeddings=[r["embedding"] for r in vectors]
embeddings=[r["embedding"] if r is not None else None for r in vectors]
if "embeddings" in include
else None,
metadatas=_clean_metadatas(metadatas)
Expand Down
16 changes: 13 additions & 3 deletions chromadb/segment/impl/vector/local_persistent_hnsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ def get_vectors(
hnsw_labels = []

results: List[Optional[VectorEmbeddingRecord]] = []


if len(target_ids) > 0:
# initializes the results list, making sure it is large enough to hold any value of id_to_index[id]
results: List[Optional[VectorEmbeddingRecord]] = [None] * len(target_ids) # Fill with None, assuming that VectorEmbeddingRecord can be replaced by None

id_to_index: Dict[str, int] = {}
for i, id in enumerate(target_ids):
if id in ids_bf:
Expand All @@ -327,9 +333,13 @@ def get_vectors(

for label, vector in zip(hnsw_labels, vectors):
id = self._label_to_id[label]
results[id_to_index[id]] = VectorEmbeddingRecord(
id=id, embedding=vector
)
if id_to_index[id] < len(results): # 确保索引在范围内
results[id_to_index[id]] = VectorEmbeddingRecord(
id=id, embedding=vector
)
else:
# 这里可以添加日志或异常处理,如果id_to_index[id]超出预期范围
pass

return results # type: ignore ## Python can't cast List with Optional to List with VectorEmbeddingRecord

Expand Down
Loading