This commit is contained in:
parent
a90ee49848
commit
e942ad51e3
|
|
@ -3,7 +3,7 @@ from pydantic import BaseModel
|
||||||
from app.core.embedding import embedder
|
from app.core.embedding import embedder
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from llama_index.vector_stores.faiss import FaissVectorStore
|
from llama_index.vector_stores.faiss import FaissVectorStore
|
||||||
from llama_index import VectorStoreIndex, ServiceContext
|
from llama_index import VectorStoreIndex, ServiceContext, StorageContext
|
||||||
import os
|
import os
|
||||||
import logging
|
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}")
|
logger.error(f"Index not found for user: {user_id} at {index_path}")
|
||||||
raise HTTPException(status_code=404, detail="用户索引不存在")
|
raise HTTPException(status_code=404, detail="用户索引不存在")
|
||||||
|
|
||||||
# 加载整个 Faiss 向量存储目录
|
# 创建 StorageContext 并加载 Faiss 向量存储目录
|
||||||
logger.info(f"Loading Faiss vector store from path: {index_path}")
|
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)
|
service_context = ServiceContext.from_defaults(embed_model=embedder, llm=None)
|
||||||
logger.info("Service context created successfully.")
|
logger.info("Service context created successfully.")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue