-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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,269% in PR #6236 (LFOSS-492
)
#6640
⚡️ Speed up method AstraDBVectorStoreComponent.get_database_object
by 1,269% in PR #6236 (LFOSS-492
)
#6640
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,4 @@ | ||||||||||||||||
import functools | ||||||||||||||||
from collections import defaultdict | ||||||||||||||||
from dataclasses import asdict, dataclass, field | ||||||||||||||||
|
||||||||||||||||
|
@@ -433,30 +434,32 @@ | |||||||||||||||
return db.get("api_endpoint") | ||||||||||||||||
|
||||||||||||||||
def get_api_endpoint(self): | ||||||||||||||||
return self.get_api_endpoint_static( | ||||||||||||||||
token=self.token, | ||||||||||||||||
environment=self.environment, | ||||||||||||||||
api_endpoint=self.api_endpoint, | ||||||||||||||||
database_name=self.database_name, | ||||||||||||||||
) | ||||||||||||||||
if not self.api_endpoint_cache: | ||||||||||||||||
self.api_endpoint_cache = self.get_api_endpoint_static_cached( | ||||||||||||||||
token=self.token, | ||||||||||||||||
environment=self.environment, | ||||||||||||||||
api_endpoint=self.api_endpoint, | ||||||||||||||||
database_name=self.database_name, | ||||||||||||||||
) | ||||||||||||||||
return self.api_endpoint_cache | ||||||||||||||||
|
||||||||||||||||
def get_keyspace(self): | ||||||||||||||||
keyspace = self.keyspace | ||||||||||||||||
|
||||||||||||||||
if keyspace: | ||||||||||||||||
return keyspace.strip() | ||||||||||||||||
|
||||||||||||||||
if self.keyspace: | ||||||||||||||||
return self.strip_keyspace(self.keyspace) | ||||||||||||||||
return None | ||||||||||||||||
Comment on lines
+447
to
449
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
def get_database_object(self, api_endpoint: str | None = None): | ||||||||||||||||
if self.database_object_cache: | ||||||||||||||||
return self.database_object_cache | ||||||||||||||||
|
||||||||||||||||
try: | ||||||||||||||||
client = DataAPIClient(token=self.token, environment=self.environment) | ||||||||||||||||
|
||||||||||||||||
return client.get_database( | ||||||||||||||||
self.database_object_cache = client.get_database( | ||||||||||||||||
api_endpoint=api_endpoint or self.get_api_endpoint(), | ||||||||||||||||
token=self.token, | ||||||||||||||||
keyspace=self.get_keyspace(), | ||||||||||||||||
) | ||||||||||||||||
return self.database_object_cache | ||||||||||||||||
Check failure on line 462 in src/backend/base/langflow/components/vectorstores/astradb.py
|
||||||||||||||||
except Exception as e: | ||||||||||||||||
msg = f"Error fetching database object: {e}" | ||||||||||||||||
raise ValueError(msg) from e | ||||||||||||||||
|
@@ -946,3 +949,22 @@ | |||||||||||||||
"search_type": self._map_search_type(), | ||||||||||||||||
"search_kwargs": search_args, | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
def __init__(self, **kwargs): | ||||||||||||||||
super().__init__(**kwargs) | ||||||||||||||||
self.api_endpoint_cache = None | ||||||||||||||||
self.database_object_cache = None | ||||||||||||||||
|
||||||||||||||||
@functools.lru_cache(maxsize=128) | ||||||||||||||||
Check failure on line 958 in src/backend/base/langflow/components/vectorstores/astradb.py
|
||||||||||||||||
def get_api_endpoint_static_cached(self, token, environment, api_endpoint, database_name): | ||||||||||||||||
return self.get_api_endpoint_static( | ||||||||||||||||
token=token, | ||||||||||||||||
environment=environment, | ||||||||||||||||
api_endpoint=api_endpoint, | ||||||||||||||||
database_name=database_name, | ||||||||||||||||
) | ||||||||||||||||
Comment on lines
+960
to
+965
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
@staticmethod | ||||||||||||||||
@functools.lru_cache(maxsize=128) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
def strip_keyspace(keyspace): | ||||||||||||||||
return keyspace.strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.