Skip to content

Commit d2cfb4e

Browse files
committed
Accept None ids in AstraDBVectorStore.add_texts
1 parent 5de66fe commit d2cfb4e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

libs/astradb/langchain_astradb/vectorstores.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,10 +1451,12 @@ def _get_documents_to_insert(
14511451
texts: Iterable[str],
14521452
embedding_vectors: Sequence[list[float] | None],
14531453
metadatas: list[dict] | None = None,
1454-
ids: list[str] | None = None,
1454+
ids: Iterable[str | None] | None = None,
14551455
) -> list[DocDict]:
14561456
if ids is None:
1457-
ids = [uuid.uuid4().hex for _ in texts]
1457+
ids_ = [uuid.uuid4().hex for _ in texts]
1458+
else:
1459+
ids_ = [uuid.uuid4().hex if id_ is None else id_ for id_ in ids]
14581460
if metadatas is None:
14591461
metadatas = [{} for _ in texts]
14601462
documents_to_insert = [
@@ -1467,7 +1469,7 @@ def _get_documents_to_insert(
14671469
for b_txt, b_emb, b_id, b_md in zip(
14681470
texts,
14691471
embedding_vectors,
1470-
ids,
1472+
ids_,
14711473
metadatas,
14721474
strict=True,
14731475
)
@@ -1483,7 +1485,7 @@ def add_texts(
14831485
self,
14841486
texts: Iterable[str],
14851487
metadatas: list[dict] | None = None,
1486-
ids: list[str] | None = None,
1488+
ids: Iterable[str | None] | None = None,
14871489
*,
14881490
batch_size: int | None = None,
14891491
batch_concurrency: int | None = None,
@@ -1624,7 +1626,7 @@ async def aadd_texts(
16241626
self,
16251627
texts: Iterable[str],
16261628
metadatas: list[dict] | None = None,
1627-
ids: list[str] | None = None,
1629+
ids: Iterable[str | None] | None = None,
16281630
*,
16291631
batch_size: int | None = None,
16301632
batch_concurrency: int | None = None,

0 commit comments

Comments
 (0)