Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core[patch]: improve index/aindex api when batch_size<n_docs #25754

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions libs/core/langchain_core/indexing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,17 @@ def index(

# mypy isn't good enough to determine that source ids cannot be None
# here due to a check that's happening above, so we check again.
for source_id in source_ids:
if source_id is None:
raise AssertionError("Source ids cannot be None here.")
if any(source_id is None for source_id in source_ids):
raise AssertionError("Source ids cannot be if cleanup=='incremental'.")

_source_ids = cast(Sequence[str], source_ids)
indexed_source_ids = cast(
Sequence[str], [source_id_assigner(doc) for doc in docs_to_index]
)

uids_to_delete = record_manager.list_keys(
group_ids=_source_ids, before=index_start_dt
group_ids=indexed_source_ids, before=index_start_dt
)
if uids_to_delete:
if indexed_source_ids and uids_to_delete:
# Then delete from vector store.
destination.delete(uids_to_delete)
# First delete from record store.
Expand Down Expand Up @@ -626,16 +627,17 @@ async def aindex(

# mypy isn't good enough to determine that source ids cannot be None
# here due to a check that's happening above, so we check again.
for source_id in source_ids:
if source_id is None:
raise AssertionError("Source ids cannot be None here.")
if any(source_id is None for source_id in source_ids):
raise AssertionError("Source ids cannot be if cleanup=='incremental'.")

_source_ids = cast(Sequence[str], source_ids)
indexed_source_ids = cast(
Sequence[str], [source_id_assigner(doc) for doc in docs_to_index]
)

uids_to_delete = await record_manager.alist_keys(
group_ids=_source_ids, before=index_start_dt
group_ids=indexed_source_ids, before=index_start_dt
)
if uids_to_delete:
if indexed_source_ids and uids_to_delete:
# Then delete from vector store.
await destination.adelete(uids_to_delete)
# First delete from record store.
Expand Down
Loading
Loading