55from fastapi import APIRouter , Body , Depends , Header , HTTPException , Path , Query
66
77from consts .model import IndexingResponse
8- from nexent .vector_database .elasticsearch_core import ElasticSearchCore
9- from services .elasticsearch_service import ElasticSearchService , get_embedding_model , get_es_core , \
10- check_knowledge_base_exist_impl
8+ from nexent .vector_database .base import VectorDatabaseCore
9+ from services .vectordatabase_service import (
10+ ElasticSearchService ,
11+ get_embedding_model ,
12+ get_vector_db_core ,
13+ check_knowledge_base_exist_impl ,
14+ )
1115from services .redis_service import get_redis_service
1216from utils .auth_utils import get_current_user_id
1317
1418router = APIRouter (prefix = "/indices" )
1519service = ElasticSearchService ()
16- logger = logging .getLogger ("elasticsearch_app " )
20+ logger = logging .getLogger ("vectordatabase_app " )
1721
1822
1923@router .get ("/check_exist/{index_name}" )
2024async def check_knowledge_base_exist (
2125 index_name : str = Path (..., description = "Name of the index to check" ),
22- es_core : ElasticSearchCore = Depends (get_es_core ),
26+ vdb_core : VectorDatabaseCore = Depends (get_vector_db_core ),
2327 authorization : Optional [str ] = Header (None )
2428):
2529 """Check if a knowledge base name exists and in which scope."""
2630 try :
2731 user_id , tenant_id = get_current_user_id (authorization )
28- return check_knowledge_base_exist_impl (index_name = index_name , es_core = es_core , user_id = user_id , tenant_id = tenant_id )
32+ return check_knowledge_base_exist_impl (index_name = index_name , vdb_core = vdb_core , user_id = user_id , tenant_id = tenant_id )
2933 except Exception as e :
3034 logger .error (
3135 f"Error checking knowledge base existence for '{ index_name } ': { str (e )} " , exc_info = True )
@@ -38,13 +42,13 @@ def create_new_index(
3842 index_name : str = Path (..., description = "Name of the index to create" ),
3943 embedding_dim : Optional [int ] = Query (
4044 None , description = "Dimension of the embedding vectors" ),
41- es_core : ElasticSearchCore = Depends (get_es_core ),
45+ vdb_core : VectorDatabaseCore = Depends (get_vector_db_core ),
4246 authorization : Optional [str ] = Header (None )
4347):
4448 """Create a new vector index and store it in the knowledge table"""
4549 try :
4650 user_id , tenant_id = get_current_user_id (authorization )
47- return ElasticSearchService .create_index (index_name , embedding_dim , es_core , user_id , tenant_id )
51+ return ElasticSearchService .create_index (index_name , embedding_dim , vdb_core , user_id , tenant_id )
4852 except Exception as e :
4953 raise HTTPException (
5054 status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = f"Error creating index: { str (e )} " )
@@ -53,15 +57,15 @@ def create_new_index(
5357@router .delete ("/{index_name}" )
5458async def delete_index (
5559 index_name : str = Path (..., description = "Name of the index to delete" ),
56- es_core : ElasticSearchCore = Depends (get_es_core ),
60+ vdb_core : VectorDatabaseCore = Depends (get_vector_db_core ),
5761 authorization : Optional [str ] = Header (None )
5862):
5963 """Delete an index and all its related data by calling the centralized service."""
6064 logger .debug (f"Received request to delete knowledge base: { index_name } " )
6165 try :
6266 user_id , tenant_id = get_current_user_id (authorization )
6367 # Call the centralized full deletion service
64- result = await ElasticSearchService .full_delete_knowledge_base (index_name , es_core , user_id )
68+ result = await ElasticSearchService .full_delete_knowledge_base (index_name , vdb_core , user_id )
6569 return result
6670 except Exception as e :
6771 logger .error (
@@ -75,13 +79,13 @@ def get_list_indices(
7579 pattern : str = Query ("*" , description = "Pattern to match index names" ),
7680 include_stats : bool = Query (
7781 False , description = "Whether to include index stats" ),
78- es_core : ElasticSearchCore = Depends (get_es_core ),
82+ vdb_core : VectorDatabaseCore = Depends (get_vector_db_core ),
7983 authorization : Optional [str ] = Header (None ),
8084):
8185 """List all user indices with optional stats"""
8286 try :
8387 user_id , tenant_id = get_current_user_id (authorization )
84- return ElasticSearchService .list_indices (pattern , include_stats , tenant_id , user_id , es_core )
88+ return ElasticSearchService .list_indices (pattern , include_stats , tenant_id , user_id , vdb_core )
8589 except Exception as e :
8690 raise HTTPException (
8791 status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = f"Error get index: { str (e )} " )
@@ -93,7 +97,7 @@ def create_index_documents(
9397 index_name : str = Path (..., description = "Name of the index" ),
9498 data : List [Dict [str , Any ]
9599 ] = Body (..., description = "Document List to process" ),
96- es_core : ElasticSearchCore = Depends (get_es_core ),
100+ vdb_core : VectorDatabaseCore = Depends (get_vector_db_core ),
97101 authorization : Optional [str ] = Header (None )
98102):
99103 """
@@ -103,7 +107,7 @@ def create_index_documents(
103107 try :
104108 user_id , tenant_id = get_current_user_id (authorization )
105109 embedding_model = get_embedding_model (tenant_id )
106- return ElasticSearchService .index_documents (embedding_model , index_name , data , es_core )
110+ return ElasticSearchService .index_documents (embedding_model , index_name , data , vdb_core )
107111 except Exception as e :
108112 error_msg = str (e )
109113 logger .error (f"Error indexing documents: { error_msg } " )
@@ -114,11 +118,11 @@ def create_index_documents(
114118@router .get ("/{index_name}/files" )
115119async def get_index_files (
116120 index_name : str = Path (..., description = "Name of the index" ),
117- es_core : ElasticSearchCore = Depends (get_es_core )
121+ vdb_core : VectorDatabaseCore = Depends (get_vector_db_core )
118122):
119123 """Get all files from an index, including those that are not yet stored in ES"""
120124 try :
121- result = await ElasticSearchService .list_files (index_name , include_chunks = False , es_core = es_core )
125+ result = await ElasticSearchService .list_files (index_name , include_chunks = False , vdb_core = vdb_core )
122126 # Transform result to match frontend expectations
123127 return {
124128 "status" : "success" ,
@@ -136,13 +140,13 @@ def delete_documents(
136140 index_name : str = Path (..., description = "Name of the index" ),
137141 path_or_url : str = Query (...,
138142 description = "Path or URL of documents to delete" ),
139- es_core : ElasticSearchCore = Depends (get_es_core )
143+ vdb_core : VectorDatabaseCore = Depends (get_vector_db_core )
140144):
141145 """Delete documents by path or URL and clean up related Redis records"""
142146 try :
143147 # First delete the documents using existing service
144148 result = ElasticSearchService .delete_documents (
145- index_name , path_or_url , es_core )
149+ index_name , path_or_url , vdb_core )
146150
147151 # Then clean up Redis records related to this specific document
148152 try :
@@ -184,10 +188,10 @@ def delete_documents(
184188
185189# Health check
186190@router .get ("/health" )
187- def health_check (es_core : ElasticSearchCore = Depends (get_es_core )):
191+ def health_check (vdb_core : VectorDatabaseCore = Depends (get_vector_db_core )):
188192 """Check API and Elasticsearch health"""
189193 try :
190194 # Try to list indices as a health check
191- return ElasticSearchService .health_check (es_core )
195+ return ElasticSearchService .health_check (vdb_core )
192196 except Exception as e :
193197 raise HTTPException (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , detail = f"{ str (e )} " )
0 commit comments