This commit is contained in:
parent
160afd1744
commit
a90ee49848
|
|
@ -4,7 +4,6 @@ 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.embeddings.huggingface import HuggingFaceEmbedding
|
||||
import os
|
||||
import logging
|
||||
|
||||
|
|
@ -22,18 +21,18 @@ def search_docs(request: QueryRequest, user_id: str = Query(..., description="
|
|||
try:
|
||||
logger.info(f"Received search request from user: {user_id} with query: {request.query}")
|
||||
|
||||
# 修正后的索引路径,确保指向具体的 index.faiss 文件
|
||||
index_path = os.path.join("index_data", user_id, "index.faiss") # 指向文件,而非目录
|
||||
# 修正后的索引路径,确保指向整个目录,而不是单个文件
|
||||
index_path = os.path.join("index_data", user_id) # 使用整个目录路径
|
||||
logger.info(f"Looking for index at path: {index_path}")
|
||||
|
||||
# 检查索引是否存在
|
||||
# 检查索引目录是否存在
|
||||
if not os.path.exists(index_path):
|
||||
logger.error(f"Index not found for user: {user_id} at {index_path}")
|
||||
raise HTTPException(status_code=404, detail="用户索引不存在")
|
||||
|
||||
# 构建 LlamaIndex 检索器
|
||||
# 加载整个 Faiss 向量存储目录
|
||||
logger.info(f"Loading Faiss vector store from path: {index_path}")
|
||||
faiss_store = FaissVectorStore.from_persist_path(index_path)
|
||||
faiss_store = FaissVectorStore.from_persist_dir(index_path) # 从目录加载
|
||||
service_context = ServiceContext.from_defaults(embed_model=embedder, llm=None)
|
||||
logger.info("Service context created successfully.")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue