File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 55from endpoint_schema import EndpointSchema
66from langchain_core .documents import Document
77from qdrant_client import models
8+ from qdrant_client .http .models import Distance , VectorParams
89
910from sparql_llm .indexing .index_resources import embedding_model , qdrant_client
1011
@@ -82,8 +83,17 @@ def init_vectordb(
8283 start_time = time .time ()
8384
8485 embeddings = list (embedding_model .embed ([d .page_content for d in docs ]))
86+
87+ collection_name = f"text2sparql-{ graph .split ('/' )[- 2 ]} "
88+ # Ensure collection exists before upserting
89+ if not qdrant_client .collection_exists (collection_name ):
90+ qdrant_client .create_collection (
91+ collection_name = collection_name ,
92+ vectors_config = VectorParams (size = embedding_model .embedding_size , distance = Distance .COSINE ),
93+ )
94+
8595 qdrant_client .upsert (
86- collection_name = f"text2sparql- { graph . split ( '/' )[ - 2 ] } " ,
96+ collection_name = collection_name ,
8797 points = models .Batch (
8898 ids = list (range (1 , len (docs ) + 1 )),
8999 vectors = [emb .tolist () for emb in embeddings ],
You can’t perform that action at this time.
0 commit comments