Skip to content

Commit f8e0375

Browse files
committed
test: fix indexing
1 parent 5fa1002 commit f8e0375

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tests/text2sparql/index.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from endpoint_schema import EndpointSchema
66
from langchain_core.documents import Document
77
from qdrant_client import models
8+
from qdrant_client.http.models import Distance, VectorParams
89

910
from 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],

0 commit comments

Comments
 (0)