From a36e11973db133052f905bb5b6e2eda3f683a827 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Fri, 23 May 2025 16:56:09 +0800 Subject: [PATCH] perf: code quality Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- astrbot/core/db/vec_db/faiss_impl/embedding_storage.py | 6 +++--- astrbot/core/db/vec_db/faiss_impl/vec_db.py | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/astrbot/core/db/vec_db/faiss_impl/embedding_storage.py b/astrbot/core/db/vec_db/faiss_impl/embedding_storage.py index 985f00cc9..262a459e3 100644 --- a/astrbot/core/db/vec_db/faiss_impl/embedding_storage.py +++ b/astrbot/core/db/vec_db/faiss_impl/embedding_storage.py @@ -9,14 +9,14 @@ import numpy as np class EmbeddingStorage: - def __init__(self, dimention: int, path: str = None): - self.dimention = dimention + def __init__(self, dimension: int, path: str = None): + self.dimension = dimension self.path = path self.index = None if path and os.path.exists(path): self.index = faiss.read_index(path) else: - base_index = faiss.IndexFlatL2(dimention) + base_index = faiss.IndexFlatL2(dimension) self.index = faiss.IndexIDMap(base_index) self.storage = {} diff --git a/astrbot/core/db/vec_db/faiss_impl/vec_db.py b/astrbot/core/db/vec_db/faiss_impl/vec_db.py index 87edad7e7..e4122e547 100644 --- a/astrbot/core/db/vec_db/faiss_impl/vec_db.py +++ b/astrbot/core/db/vec_db/faiss_impl/vec_db.py @@ -91,9 +91,7 @@ class FaissVecDB(BaseVecDB): return [] result_docs = [] - idx_pos = {} - for idx, fetch_doc in enumerate(fetched_docs): - idx_pos[fetch_doc["id"]] = idx + idx_pos = {fetch_doc["id"]: idx for idx, fetch_doc in enumerate(fetched_docs)} for i, indice_idx in enumerate(indices[0]): pos = idx_pos.get(indice_idx) if pos is None: