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

⚡️ Speed up method AstraDBVectorStoreComponent._initialize_collection_options by 38% in PR #6202 (codeflash/optimize-pr6028-2025-02-07T20.23.30) #6204

Closed
Show file tree
Hide file tree
Changes from all 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
32 changes: 14 additions & 18 deletions src/backend/base/langflow/components/vectorstores/astradb.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,19 +390,18 @@
token=self.token,
keyspace=self.get_keyspace(),
)
return self._database

Check failure on line 393 in src/backend/base/langflow/components/vectorstores/astradb.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (TRY300)

src/backend/base/langflow/components/vectorstores/astradb.py:393:13: TRY300 Consider moving this statement to an `else` block
except Exception as e:
msg = f"Error fetching database object: {e}"
raise ValueError(msg) from e
raise ValueError(f"Error fetching database object: {e}") from e

Check failure on line 395 in src/backend/base/langflow/components/vectorstores/astradb.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (TRY003)

src/backend/base/langflow/components/vectorstores/astradb.py:395:19: TRY003 Avoid specifying long messages outside the exception class

Check failure on line 395 in src/backend/base/langflow/components/vectorstores/astradb.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (EM102)

src/backend/base/langflow/components/vectorstores/astradb.py:395:30: EM102 Exception must not use an f-string literal, assign to variable first

def collection_data(self, collection_name: str, database: Database | None = None):
try:
if database is None:
database = self.get_database_object()
if database is None:
database = self.get_database_object()

try:
collection = database.get_collection(collection_name, keyspace=self.get_keyspace())
return collection.estimated_document_count()
except Exception as e:

Check failure on line 404 in src/backend/base/langflow/components/vectorstores/astradb.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (BLE001)

src/backend/base/langflow/components/vectorstores/astradb.py:404:16: BLE001 Do not catch blind exception: `Exception`
self.log(f"Error checking collection data: {e}")
return None

Expand Down Expand Up @@ -452,21 +451,18 @@
keyspace = self.get_keyspace()
collection_list = database.list_collections(keyspace=keyspace)

results = []
for col in collection_list:
records_count = self.collection_data(collection_name=col.name, database=database)
vector_service = col.options.vector.service if col.options.vector else None
results.append(
{
"name": col.name,
"records": records_count,
"provider": vector_service.provider if vector_service else None,
"icon": "",
"model": vector_service.model_name if vector_service else None,
}
)
results = [
{
"name": col.name,
"records": self.collection_data(collection_name=col.name, database=database),
"provider": col.options.vector.service.provider if col.options.vector else None,
"icon": "",
"model": col.options.vector.service.model_name if col.options.vector else None,
}
for col in collection_list
]

return results

Check failure on line 465 in src/backend/base/langflow/components/vectorstores/astradb.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (RET504)

src/backend/base/langflow/components/vectorstores/astradb.py:465:16: RET504 Unnecessary assignment to `results` before `return` statement

def reset_collection_list(self, build_config: dict):
# Get the list of options we have based on the token provided
Expand Down
Loading
Loading