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:
parent
3cd9ba688e
commit
a44130d3c3
3 changed files with 36 additions and 25 deletions
|
|
@ -161,11 +161,11 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||||
dialog_inputs=asdict(NewDatabaseInput()),
|
dialog_inputs=asdict(NewDatabaseInput()),
|
||||||
combobox=True,
|
combobox=True,
|
||||||
),
|
),
|
||||||
StrInput(
|
DropdownInput(
|
||||||
name="api_endpoint",
|
name="api_endpoint",
|
||||||
display_name="Astra DB API Endpoint",
|
display_name="Astra DB API Endpoint",
|
||||||
info="The API Endpoint for the Astra DB instance. Supercedes database selection.",
|
info="The API Endpoint for the Astra DB instance. Supercedes database selection.",
|
||||||
show=False,
|
advanced=True,
|
||||||
),
|
),
|
||||||
DropdownInput(
|
DropdownInput(
|
||||||
name="keyspace",
|
name="keyspace",
|
||||||
|
|
@ -224,7 +224,6 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||||
separator=" ",
|
separator=" ",
|
||||||
show=False,
|
show=False,
|
||||||
value="",
|
value="",
|
||||||
advanced=True,
|
|
||||||
),
|
),
|
||||||
IntInput(
|
IntInput(
|
||||||
name="number_of_results",
|
name="number_of_results",
|
||||||
|
|
@ -448,14 +447,14 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||||
for db in db_list:
|
for db in db_list:
|
||||||
try:
|
try:
|
||||||
# Get the API endpoint for the database
|
# 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
|
# Get the number of collections
|
||||||
try:
|
try:
|
||||||
# Get the number of collections in the database
|
# Get the number of collections in the database
|
||||||
num_collections = len(
|
num_collections = len(
|
||||||
client.get_database(
|
client.get_database(
|
||||||
api_endpoint,
|
api_endpoints[0],
|
||||||
token=token,
|
token=token,
|
||||||
).list_collection_names()
|
).list_collection_names()
|
||||||
)
|
)
|
||||||
|
|
@ -466,7 +465,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||||
|
|
||||||
# Add the database to the dictionary
|
# Add the database to the dictionary
|
||||||
db_info_dict[db.name] = {
|
db_info_dict[db.name] = {
|
||||||
"api_endpoint": api_endpoint,
|
"api_endpoints": api_endpoints,
|
||||||
"keyspaces": db.keyspaces,
|
"keyspaces": db.keyspaces,
|
||||||
"collections": num_collections,
|
"collections": num_collections,
|
||||||
"status": db.status if db.status != "ACTIVE" else None,
|
"status": db.status if db.status != "ACTIVE" else None,
|
||||||
|
|
@ -509,7 +508,8 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Otherwise, get the URL from the database list
|
# 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):
|
def get_api_endpoint(self):
|
||||||
return self.get_api_endpoint_static(
|
return self.get_api_endpoint_static(
|
||||||
|
|
@ -577,7 +577,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||||
"name": name,
|
"name": name,
|
||||||
"status": info["status"],
|
"status": info["status"],
|
||||||
"collections": info["collections"],
|
"collections": info["collections"],
|
||||||
"api_endpoint": info["api_endpoint"],
|
"api_endpoints": info["api_endpoints"],
|
||||||
"keyspaces": info["keyspaces"],
|
"keyspaces": info["keyspaces"],
|
||||||
"org_id": info["org_id"],
|
"org_id": info["org_id"],
|
||||||
}
|
}
|
||||||
|
|
@ -773,6 +773,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||||
# Reset selections if value not in options
|
# Reset selections if value not in options
|
||||||
if database_config["value"] not in database_config["options"]:
|
if database_config["value"] not in database_config["options"]:
|
||||||
database_config["value"] = ""
|
database_config["value"] = ""
|
||||||
|
build_config["api_endpoint"]["options"] = []
|
||||||
build_config["api_endpoint"]["value"] = ""
|
build_config["api_endpoint"]["value"] = ""
|
||||||
build_config["collection_name"]["show"] = False
|
build_config["collection_name"]["show"] = False
|
||||||
|
|
||||||
|
|
@ -786,6 +787,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||||
# Reset database configuration
|
# Reset database configuration
|
||||||
database_config = build_config["database_name"]
|
database_config = build_config["database_name"]
|
||||||
database_config.update({"options": [], "options_metadata": [], "value": "", "show": False})
|
database_config.update({"options": [], "options_metadata": [], "value": "", "show": False})
|
||||||
|
build_config["api_endpoint"]["options"] = []
|
||||||
build_config["api_endpoint"]["value"] = ""
|
build_config["api_endpoint"]["value"] = ""
|
||||||
|
|
||||||
# Reset collection configuration
|
# Reset collection configuration
|
||||||
|
|
@ -828,13 +830,6 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||||
build_config["search_method"]["options"] = ["Vector Search"]
|
build_config["search_method"]["options"] = ["Vector Search"]
|
||||||
build_config["search_method"]["value"] = "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
|
return build_config
|
||||||
|
|
||||||
async def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None) -> dict:
|
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"]
|
build_config["lexical_terms"]["value"] = "" if is_vector_search else build_config["lexical_terms"]["value"]
|
||||||
|
|
||||||
# Disable reranker disabling if hybrid search is selected
|
# 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_disable"] = not is_vector_search
|
||||||
build_config["reranker"]["toggle_value"] = True
|
build_config["reranker"]["toggle_value"] = True
|
||||||
build_config["reranker"]["value"] = build_config["reranker"]["options"][0]
|
build_config["reranker"]["value"] = build_config["reranker"]["options"][0]
|
||||||
|
|
@ -926,7 +922,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||||
{
|
{
|
||||||
"status": "PENDING",
|
"status": "PENDING",
|
||||||
"collections": 0,
|
"collections": 0,
|
||||||
"api_endpoint": None,
|
"api_endpoints": [],
|
||||||
"keyspaces": [self.get_keyspace()],
|
"keyspaces": [self.get_keyspace()],
|
||||||
"org_id": None,
|
"org_id": None,
|
||||||
}
|
}
|
||||||
|
|
@ -999,7 +995,12 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||||
|
|
||||||
# Get the api endpoint for the selected database
|
# Get the api endpoint for the selected database
|
||||||
index = build_config["database_name"]["options"].index(field_value)
|
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
|
# Get the org_id for the selected database
|
||||||
org_id = build_config["database_name"]["options_metadata"][index]["org_id"]
|
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
|
lex_enabled = col_options.lexical and col_options.lexical.enabled
|
||||||
user_hyb_enabled = build_config["search_method"]["value"] == "Hybrid Search"
|
user_hyb_enabled = build_config["search_method"]["value"] == "Hybrid Search"
|
||||||
|
|
||||||
# Show lexical terms if the collection is hybrid enabled
|
# Reranker visible when both the collection supports it and the user selected Hybrid
|
||||||
build_config["lexical_terms"]["show"] = hyb_enabled and lex_enabled and user_hyb_enabled
|
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
|
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
Loading…
Add table
Add a link
Reference in a new issue