@@ -158,23 +158,34 @@ def connection_check_and_get_vector_dimensions(self):
158
158
WHERE type = 'VECTOR' AND name = 'vector'
159
159
RETURN options.indexConfig['vector.dimensions'] AS vector_dimensions
160
160
""" )
161
+
162
+ result_chunks = self .graph .query ("""match (c:Chunk) return size(c.embedding) as embeddingSize, count(*) as chunks,
163
+ count(c.embedding) as hasEmbedding
164
+ """ )
165
+
161
166
embedding_model = os .getenv ('EMBEDDING_MODEL' )
162
167
embeddings , application_dimension = load_embedding_model (embedding_model )
163
168
logging .info (f'embedding model:{ embeddings } and dimesion:{ application_dimension } ' )
169
+ # print(chunks_exists)
164
170
165
171
if self .graph :
166
172
if len (db_vector_dimension ) > 0 :
167
173
return {'db_vector_dimension' : db_vector_dimension [0 ]['vector_dimensions' ], 'application_dimension' :application_dimension , 'message' :"Connection Successful" }
168
174
else :
169
- logging .info ("Vector index does not exist in database" )
170
- return {'db_vector_dimension' : 0 , 'application_dimension' :application_dimension , 'message' :"Connection Successful" }
175
+ if len (db_vector_dimension ) == 0 and len (result_chunks ) == 0 :
176
+ logging .info ("Chunks and vector index does not exists in database" )
177
+ return {'db_vector_dimension' : 0 , 'application_dimension' :application_dimension , 'message' :"Connection Successful" ,"chunks_exists" :False }
178
+ elif len (db_vector_dimension ) == 0 and result_chunks [0 ]['hasEmbedding' ]== 0 and result_chunks [0 ]['chunks' ] > 0 :
179
+ return {'db_vector_dimension' : 0 , 'application_dimension' :application_dimension , 'message' :"Connection Successful" ,"chunks_exists" :True }
180
+ else :
181
+ return {'message' :"Connection Successful" }
171
182
172
183
def execute_query (self , query , param = None ):
173
184
return self .graph .query (query , param )
174
185
175
186
def get_current_status_document_node (self , file_name ):
176
187
query = """
177
- MATCH(d:Document {fileName : $file_name}) RETURN d.status AS Status , d.processingTime AS processingTime,
188
+ MATCH(d:Document {fileName : $file_name}) RETURN d.stats AS Status , d.processingTime AS processingTime,
178
189
d.nodeCount AS nodeCount, d.model as model, d.relationshipCount as relationshipCount,
179
190
d.total_pages AS total_pages, d.total_chunks AS total_chunks , d.fileSize as fileSize,
180
191
d.is_cancelled as is_cancelled, d.processed_chunk as processed_chunk, d.fileSource as fileSource
@@ -322,15 +333,16 @@ def merge_duplicate_nodes(self,duplicate_nodes_list):
322
333
param = {"rows" :nodes_list }
323
334
return self .execute_query (query ,param )
324
335
325
- def drop_create_vector_index (self , is_vector_index_recreate ):
336
+ def drop_create_vector_index (self , isVectorIndexExist ):
326
337
"""
327
338
drop and create the vector index when vector index dimesion are different.
328
339
"""
329
340
embedding_model = os .getenv ('EMBEDDING_MODEL' )
330
341
embeddings , dimension = load_embedding_model (embedding_model )
331
- if is_vector_index_recreate == 'true' :
332
- self .graph .query ("""drop index vector""" )
333
342
343
+ if isVectorIndexExist == 'true' :
344
+ self .graph .query ("""drop index vector""" )
345
+ # self.graph.query("""drop index vector""")
334
346
self .graph .query ("""CREATE VECTOR INDEX `vector` if not exists for (c:Chunk) on (c.embedding)
335
347
OPTIONS {indexConfig: {
336
348
`vector.dimensions`: $dimensions,
@@ -341,4 +353,4 @@ def drop_create_vector_index(self, is_vector_index_recreate):
341
353
"dimensions" : dimension
342
354
}
343
355
)
344
- return "Drop and Re-Create vector index succesfully"
356
+ return "Drop and Re-Create vector index succesfully"
0 commit comments