Skip to content

Conversation

slekkala1
Copy link
Contributor

What does this PR do?

Add Open AI Compatible vector store file batches api. This functionality is needed to attach many files to a vector store as a batch.
#3533

API Stubs have been merged #3615
Adds persistence for file batches as discussed in diff #3544
(Used claude code for generation and reviewed by me)

Test Plan

  1. Unit tests pass
  2. Also verified the cc-vec integration with LLamaStackClient works with the file batches api. https://github.com/raghotham/cc-vec
  3. Integration tests pass

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 1, 2025
@slekkala1 slekkala1 force-pushed the add-vs-file-batches-and-tests branch from ac1aa70 to 0f459be Compare October 1, 2025 22:23
@slekkala1 slekkala1 marked this pull request as ready for review October 1, 2025 22:28
asyncio.create_task(self._process_file_batch_async(batch_id, batch_info))

# Run cleanup if needed (throttled to once every 1 day)
asyncio.create_task(self._cleanup_expired_file_batches_if_needed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd only want to spawn one such task, right? Now every create request adds one of these tasks.

Copy link
Contributor Author

@slekkala1 slekkala1 Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the throttling check before create_task

Comment on lines 966 to 968
VectorStoreChunkingStrategyStatic(**chunking_strategy)
if chunking_strategy.get("type") == "static"
else VectorStoreChunkingStrategyAuto(**chunking_strategy)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think pydantic has a way of handling thing for you. TypeAdapter or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes TypeAdapter works, thanks for recommendation.

Comment on lines 970 to 971
await self.openai_attach_file_to_vector_store(
vector_store_id=vector_store_id,
file_id=file_id,
attributes=attributes,
chunking_strategy=chunking_strategy_obj,
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for... await... would process each task in sequence. Do we want them in parallel instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add concurrency for attaching files

@slekkala1 slekkala1 force-pushed the add-vs-file-batches-and-tests branch from 0f459be to d0bfdc7 Compare October 2, 2025 21:56
@slekkala1 slekkala1 marked this pull request as draft October 3, 2025 17:55
@slekkala1 slekkala1 force-pushed the add-vs-file-batches-and-tests branch from d0bfdc7 to 42ebf66 Compare October 3, 2025 18:04
@slekkala1 slekkala1 marked this pull request as ready for review October 3, 2025 18:34
Comment on lines 296 to 298
self.openai_file_batches: dict[str, dict[str, Any]] = {}
self._file_batch_tasks: dict[str, asyncio.Task[None]] = {}
self._last_file_batch_cleanup_time = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this has been the pattern, but should we just put this in the mixin's init and have subclasses call it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I agree, this list is growing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 1078 to 1080
# If cancellation fails because batch is already completed, that's acceptable
if "Cannot cancel" in str(e) or "already completed" in str(e):
pytest.skip(f"Batch completed too quickly to cancel: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't inspire confidence for this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improved by increasing the number of file batches and removing the try catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cancel test is finishing pretty fast even with 1000 files in a batch, hard cancel it before it completes.

)
assert search_response is not None


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test that actually tries to retrieve some context that verifies that the files are actually saved to the vector store?

Copy link
Contributor Author

@slekkala1 slekkala1 Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this was tested via cc-vec integration, where it retrieved files from vector store after attaching via these apis.
Let me add one integration test for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added integration test

@slekkala1 slekkala1 force-pushed the add-vs-file-batches-and-tests branch 2 times, most recently from c9be8c1 to 510ace2 Compare October 3, 2025 21:48
@slekkala1
Copy link
Contributor Author

Cancel test doesnt work as the batches complete too fast even with 1000 files, so expected failure in CI

Copy link
Contributor

@ehhuang ehhuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@slekkala1 slekkala1 force-pushed the add-vs-file-batches-and-tests branch from 8da19a9 to 310dacd Compare October 6, 2025 17:17
@slekkala1 slekkala1 force-pushed the add-vs-file-batches-and-tests branch 2 times, most recently from 16742e2 to 569ede7 Compare October 6, 2025 17:54
@slekkala1 slekkala1 force-pushed the add-vs-file-batches-and-tests branch from 130eb85 to 6533340 Compare October 6, 2025 22:10
@slekkala1 slekkala1 merged commit bba9957 into main Oct 6, 2025
21 checks passed
@slekkala1 slekkala1 deleted the add-vs-file-batches-and-tests branch October 6, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants