fix: Manage multi-region databases and better handle lexical search in Astra DB (#9385)

* Fix display of reranker and lexical terms

* API endpoint selection enabled

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* Update src/backend/base/langflow/components/vectorstores/astradb.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Update src/backend/base/langflow/components/vectorstores/astradb.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* [autofix.ci] apply automated fixes

* Update astradb.py

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Eric Hare 2025-08-21 12:08:47 -07:00 committed by GitHub
commit a44130d3c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 25 deletions

View file

@ -161,11 +161,11 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
dialog_inputs=asdict(NewDatabaseInput()),
combobox=True,
),
StrInput(
DropdownInput(
name="api_endpoint",
display_name="Astra DB API Endpoint",
info="The API Endpoint for the Astra DB instance. Supercedes database selection.",
show=False,
advanced=True,
),
DropdownInput(
name="keyspace",
@ -224,7 +224,6 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
separator=" ",
show=False,
value="",
advanced=True,
),
IntInput(
name="number_of_results",
@ -448,14 +447,14 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
for db in db_list:
try:
# Get the API endpoint for the database
api_endpoint = db.regions[0].api_endpoint
api_endpoints = [db_reg.api_endpoint for db_reg in db.regions]
# Get the number of collections
try:
# Get the number of collections in the database
num_collections = len(
client.get_database(
api_endpoint,
api_endpoints[0],
token=token,
).list_collection_names()
)
@ -466,7 +465,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
# Add the database to the dictionary
db_info_dict[db.name] = {
"api_endpoint": api_endpoint,
"api_endpoints": api_endpoints,
"keyspaces": db.keyspaces,
"collections": num_collections,
"status": db.status if db.status != "ACTIVE" else None,
@ -509,7 +508,8 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
return None
# Otherwise, get the URL from the database list
return db.get("api_endpoint")
endpoints = db.get("api_endpoints") or []
return endpoints[0] if endpoints else None
def get_api_endpoint(self):
return self.get_api_endpoint_static(
@ -577,7 +577,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
"name": name,
"status": info["status"],
"collections": info["collections"],
"api_endpoint": info["api_endpoint"],
"api_endpoints": info["api_endpoints"],
"keyspaces": info["keyspaces"],
"org_id": info["org_id"],
}
@ -773,6 +773,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
# Reset selections if value not in options
if database_config["value"] not in database_config["options"]:
database_config["value"] = ""
build_config["api_endpoint"]["options"] = []
build_config["api_endpoint"]["value"] = ""
build_config["collection_name"]["show"] = False
@ -786,6 +787,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
# Reset database configuration
database_config = build_config["database_name"]
database_config.update({"options": [], "options_metadata": [], "value": "", "show": False})
build_config["api_endpoint"]["options"] = []
build_config["api_endpoint"]["value"] = ""
# Reset collection configuration
@ -828,13 +830,6 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
build_config["search_method"]["options"] = ["Vector Search"]
build_config["search_method"]["value"] = "Vector Search"
# Set reranker and lexical terms options based on search method
build_config["reranker"]["toggle_value"] = True
build_config["reranker"]["show"] = build_config["search_method"]["value"] == "Hybrid Search"
build_config["reranker"]["toggle_disable"] = build_config["search_method"]["value"] == "Hybrid Search"
if build_config["reranker"]["show"]:
build_config["search_type"]["value"] = "Similarity"
return build_config
async def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None) -> dict:
@ -892,6 +887,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
build_config["lexical_terms"]["value"] = "" if is_vector_search else build_config["lexical_terms"]["value"]
# Disable reranker disabling if hybrid search is selected
build_config["reranker"]["show"] = not is_vector_search
build_config["reranker"]["toggle_disable"] = not is_vector_search
build_config["reranker"]["toggle_value"] = True
build_config["reranker"]["value"] = build_config["reranker"]["options"][0]
@ -926,7 +922,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
{
"status": "PENDING",
"collections": 0,
"api_endpoint": None,
"api_endpoints": [],
"keyspaces": [self.get_keyspace()],
"org_id": None,
}
@ -999,7 +995,12 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
# Get the api endpoint for the selected database
index = build_config["database_name"]["options"].index(field_value)
build_config["api_endpoint"]["value"] = build_config["database_name"]["options_metadata"][index]["api_endpoint"]
build_config["api_endpoint"]["options"] = build_config["database_name"]["options_metadata"][index][
"api_endpoints"
]
build_config["api_endpoint"]["value"] = build_config["database_name"]["options_metadata"][index][
"api_endpoints"
][0]
# Get the org_id for the selected database
org_id = build_config["database_name"]["options_metadata"][index]["org_id"]
@ -1077,8 +1078,18 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
lex_enabled = col_options.lexical and col_options.lexical.enabled
user_hyb_enabled = build_config["search_method"]["value"] == "Hybrid Search"
# Show lexical terms if the collection is hybrid enabled
build_config["lexical_terms"]["show"] = hyb_enabled and lex_enabled and user_hyb_enabled
# Reranker visible when both the collection supports it and the user selected Hybrid
hybrid_active = bool(hyb_enabled and user_hyb_enabled)
build_config["reranker"]["show"] = hybrid_active
build_config["reranker"]["toggle_value"] = hybrid_active
build_config["reranker"]["toggle_disable"] = False # allow user to toggle if visible
# If hybrid is active, lock search_type to "Similarity"
if hybrid_active:
build_config["search_type"]["value"] = "Similarity"
# Show the lexical terms option only if the collection enables lexical search
build_config["lexical_terms"]["show"] = bool(lex_enabled)
return build_config

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long