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.get_database_object by 1,126% in PR #6087 (codeflash/optimize-pr6085-2025-02-03T14.05.09) #6088

Closed
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
6 changes: 4 additions & 2 deletions src/backend/base/langflow/components/vectorstores/astradb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from collections import defaultdict
from dataclasses import dataclass, field
from functools import lru_cache

from astrapy import AstraDBAdmin, DataAPIClient, Database
from langchain_astradb import AstraDBVectorStore, CollectionVectorServiceOptions
Expand Down Expand Up @@ -367,6 +368,7 @@
# Otherwise, get the URL from the database list
return cls.get_database_list_static(token=token, environment=environment).get(database_name).get("api_endpoint")

@lru_cache(maxsize=32)

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

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (B019)

src/backend/base/langflow/components/vectorstores/astradb.py:371:5: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
def get_api_endpoint(self, *, api_endpoint: str | None = None):
return self.get_api_endpoint_static(
token=self.token,
Expand All @@ -378,6 +380,7 @@
def get_keyspace(self):
return self._keyspace

@lru_cache(maxsize=32)

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

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (B019)

src/backend/base/langflow/components/vectorstores/astradb.py:383:5: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
def get_database_object(self, api_endpoint: str | None = None):
try:
return self._client.get_database(
Expand All @@ -386,8 +389,7 @@
keyspace=self._keyspace,
)
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 392 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:392:19: TRY003 Avoid specifying long messages outside the exception class

Check failure on line 392 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:392: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:
Expand Down
Loading