diff --git a/app/api/search.py b/app/api/search.py index 010dc1c..61b8a78 100644 --- a/app/api/search.py +++ b/app/api/search.py @@ -3,7 +3,7 @@ from pydantic import BaseModel from app.core.embedding import embedder from app.core.config import settings from llama_index.vector_stores.faiss import FaissVectorStore -from llama_index import VectorStoreIndex, ServiceContext +from llama_index import VectorStoreIndex, ServiceContext, StorageContext import os import logging @@ -30,9 +30,12 @@ def search_docs(request: QueryRequest, user_id: str = Query(..., description=" logger.error(f"Index not found for user: {user_id} at {index_path}") raise HTTPException(status_code=404, detail="用户索引不存在") - # 加载整个 Faiss 向量存储目录 + # 创建 StorageContext 并加载 Faiss 向量存储目录 logger.info(f"Loading Faiss vector store from path: {index_path}") - faiss_store = FaissVectorStore.from_persist_dir(index_path) # 从目录加载 + storage_context = StorageContext.from_defaults(persist_dir=index_path) + + # 加载 Faiss 向量存储 + faiss_store = FaissVectorStore.from_persist_path(storage_context) service_context = ServiceContext.from_defaults(embed_model=embedder, llm=None) logger.info("Service context created successfully.")