-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #31 Compute vector store usage bytes in `create_vector_store` and `create_vector_store_file` functions. * **`impl/routes_v2/vector_stores.py`**: - Import `os` and `HTTPException`. - Compute `usage_bytes` in `create_vector_store` by summing `usage_bytes` of each file. - Compute `usage_bytes` in `create_vector_store_file` by reading file size from the database. - Return `DeleteVectorStoreFileResponse` in `delete_vector_store_file`. * **`client/.github/workflows/run-tests.yml`**: - Add a new job for running vector store bytes tests. * **`client/tests/astra-assistants/test_vector_store_bytes.py`**: - Add a new test file to verify the `usage_bytes` attribute for vector stores. - Set up the test environment and write a test function that creates a vector store, attaches files to it, and verifies the `usage_bytes` attribute. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/datastax/astra-assistants-api/issues/31?shareId=XXXX-XXXX-XXXX-XXXX).
- Loading branch information
Showing
3 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
import pytest | ||
from impl.routes_v2.vector_stores import create_vector_store, create_vector_store_file | ||
from openapi_server_v2.models.create_vector_store_request import CreateVectorStoreRequest | ||
from openapi_server_v2.models.create_vector_store_file_request import CreateVectorStoreFileRequest | ||
from openapi_server_v2.models.vector_store_object import VectorStoreObject | ||
from openapi_server_v2.models.vector_store_file_object import VectorStoreFileObject | ||
from impl.astra_vector import CassandraClient | ||
|
||
@pytest.fixture(scope="module") | ||
def astradb(): | ||
# Setup Cassandra client | ||
client = CassandraClient() | ||
yield client | ||
client.close() | ||
|
||
def test_vector_store_usage_bytes(astradb): | ||
# Create a vector store | ||
vector_store_request = CreateVectorStoreRequest(name="Test Vector Store", file_ids=[]) | ||
vector_store: VectorStoreObject = create_vector_store(vector_store_request, astradb) | ||
|
||
# Attach files to the vector store | ||
file_paths = ["./tests/fixtures/sample1.txt", "./tests/fixtures/sample2.txt"] | ||
total_usage_bytes = 0 | ||
|
||
for file_path in file_paths: | ||
file_size = os.path.getsize(file_path) | ||
total_usage_bytes += file_size | ||
|
||
file_request = CreateVectorStoreFileRequest(file_id=file_path) | ||
vector_store_file: VectorStoreFileObject = create_vector_store_file(vector_store.id, file_request, astradb) | ||
assert vector_store_file.usage_bytes == file_size | ||
|
||
# Verify the usage_bytes attribute of the vector store | ||
updated_vector_store: VectorStoreObject = create_vector_store(vector_store_request, astradb) | ||
assert updated_vector_store.usage_bytes == total_usage_bytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters