This commit is contained in:
hailin 2025-05-10 03:04:16 +08:00
parent a90ee49848
commit e942ad51e3
1 changed files with 6 additions and 3 deletions

View File

@ -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.")