Skip to content

Commit 7812861

Browse files
author
Nikos Papailiou
committed
Use groups instead of os.path.join and register arrays with relative paths
1 parent cae0cab commit 7812861

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

apis/python/src/tiledb/vector_search/index.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import numpy as np
44
from tiledb.vector_search.module import *
55

6+
CENTROIDS_ARRAY_NAME = "centroids.tdb"
7+
INDEX_ARRAY_NAME = "index.tdb"
8+
IDS_ARRAY_NAME = "ids.tdb"
9+
PARTS_ARRAY_NAME = "parts.tdb"
610

711
class Index:
812
def query(self, targets: np.ndarray, k=10, nqueries=10, nthreads=8, nprobe=1):
@@ -83,10 +87,11 @@ class IVFFlatIndex(Index):
8387
def __init__(
8488
self, uri, dtype: np.dtype, memory_budget: int = -1, ctx: "Ctx" = None
8589
):
86-
self.parts_db_uri = os.path.join(uri, "parts.tdb")
87-
self.centroids_uri = os.path.join(uri, "centroids.tdb")
88-
self.index_uri = os.path.join(uri, "index.tdb")
89-
self.ids_uri = os.path.join(uri, "ids.tdb")
90+
group = tiledb.Group(uri)
91+
self.parts_db_uri = group[PARTS_ARRAY_NAME].uri
92+
self.centroids_uri = group[CENTROIDS_ARRAY_NAME].uri
93+
self.index_uri = group[INDEX_ARRAY_NAME].uri
94+
self.ids_uri = group[IDS_ARRAY_NAME].uri
9095
self.dtype = dtype
9196
self.memory_budget = memory_budget
9297
self.ctx = ctx

apis/python/src/tiledb/vector_search/ingestion.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def create_arrays(
224224
)
225225
logger.info(parts_schema)
226226
tiledb.Array.create(parts_uri, parts_schema)
227-
group.add(parts_uri, name=PARTS_ARRAY_NAME)
227+
group.add(PARTS_ARRAY_NAME, name=PARTS_ARRAY_NAME, relative=True)
228228

229229
elif index_type == "IVF_FLAT":
230230
centroids_uri = f"{group.uri}/{CENTROIDS_ARRAY_NAME}"
@@ -272,7 +272,7 @@ def create_arrays(
272272
)
273273
logger.info(centroids_schema)
274274
tiledb.Array.create(centroids_uri, centroids_schema)
275-
group.add(centroids_uri, name=CENTROIDS_ARRAY_NAME)
275+
group.add(CENTROIDS_ARRAY_NAME, name=CENTROIDS_ARRAY_NAME, relative=True)
276276

277277
if not tiledb.array_exists(index_uri):
278278
logger.info("Creating index array")
@@ -294,7 +294,7 @@ def create_arrays(
294294
)
295295
logger.info(index_schema)
296296
tiledb.Array.create(index_uri, index_schema)
297-
group.add(index_uri, name=INDEX_ARRAY_NAME)
297+
group.add(INDEX_ARRAY_NAME, name=INDEX_ARRAY_NAME, relative=True)
298298

299299
if not tiledb.array_exists(ids_uri):
300300
logger.info("Creating ids array")
@@ -316,7 +316,7 @@ def create_arrays(
316316
)
317317
logger.info(ids_schema)
318318
tiledb.Array.create(ids_uri, ids_schema)
319-
group.add(ids_uri, name=IDS_ARRAY_NAME)
319+
group.add(IDS_ARRAY_NAME, name=IDS_ARRAY_NAME, relative=True)
320320

321321
if not tiledb.array_exists(parts_uri):
322322
logger.info("Creating parts array")
@@ -346,7 +346,7 @@ def create_arrays(
346346
)
347347
logger.info(parts_schema)
348348
tiledb.Array.create(parts_uri, parts_schema)
349-
group.add(parts_uri, name=PARTS_ARRAY_NAME)
349+
group.add(PARTS_ARRAY_NAME, name=PARTS_ARRAY_NAME, relative=True)
350350

351351
vfs = tiledb.VFS()
352352
if vfs.is_dir(partial_write_array_dir_uri):

0 commit comments

Comments
 (0)