-
Notifications
You must be signed in to change notification settings - Fork 16
Multi bucket support and index advisor tool addition #20
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
base: main
Are you sure you want to change the base?
Conversation
Eyal-CB
commented
Jul 15, 2025
- Removed single bucket bootstrapping, now requiring the bucket to be sent alongside scope (and collection when needed) to all tools.
- Added a tool to simplify index advisor queries. The tool accepts a query and keyspace, calls the index advisor on the query and returns a simplified response including the existing index and recommendations where applicable.
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.
Summary of Changes
Hello @Eyal-CB, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly enhances the server's capabilities by introducing full multi-bucket support, allowing operations to target specific buckets dynamically. Additionally, it adds a new utility tool to assist users with N1QL index recommendations, streamlining query optimization workflows.
Highlights
- Multi-Bucket Support: The server no longer requires a default bucket to be configured at startup. Instead, all data access operations (get, upsert, delete documents, run SQL++ queries, get scopes/collections, get schema) now explicitly require a
bucket_name
parameter, enabling interaction with multiple buckets. - New Index Advisor Tool: A new tool,
advise_index_for_sql_plus_plus_query
, has been added. It simplifies the process of getting index recommendations for SQL++ queries by taking a query, bucket, and scope, then returning existing indexes and suggested improvements.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces multi-bucket support and a new index advisor tool. My review highlights a critical bug in the new tool that could cause a server crash and suggests improvements to error handling.
@Eyal-CB Thanks for the contribution. |
…base cluster, including their bucket settings.
Thanks @nithishr . I've added the bucket list functionality tool. |
…nd aligned pull request code to new structure
@nithishr Updated feature to align with new code structure |
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.
Code Review
This pull request introduces multi-bucket support and adds a new index advisor tool. The code is generally well-written and the changes are logical. I've identified a potential issue in the test_connection
function that needs to be addressed. Additionally, I've made several medium-severity suggestions to improve maintainability by reducing code duplication and enhancing readability in the new advise_index_for_sql_plus_plus_query
tool. Overall, the changes are well-structured and the new features are great additions.
src/tools/server.py
Outdated
if bucket_name is not None: | ||
try: | ||
bucket = ensure_bucket_connection(ctx, bucket_name) | ||
except Exception as e: | ||
return { | ||
"status": "error", | ||
"cluster_connected": cluster_connected, | ||
"bucket_connected": bucket_connected, | ||
"error": str(e), | ||
"message": f"Failed to connect to bucket named {bucket_name}", | ||
} |
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.
There's a potential issue in this function. If a bucket_name
is provided and the connection to it fails, the function returns an error message. However, if the connection is successful, there isn't an explicit return statement to indicate success. This could lead to unexpected behavior or None
being returned in successful cases.
I've provided a suggestion that fixes this bug by adding a success return path for a successful bucket connection. The suggestion also slightly refactors the function to improve clarity by removing unused variables.
try:
cluster = ensure_cluster_connection(ctx)
cluster_connected = True
if bucket_name is not None:
try:
bucket = ensure_bucket_connection(ctx, bucket_name)
return {
"status": "success",
"cluster_connected": cluster_connected,
"message": f"Successfully connected to Couchbase cluster and bucket {bucket_name}",
}
except Exception as e:
return {
"status": "error",
"cluster_connected": cluster_connected,
"error": str(e),
"message": f"Failed to connect to bucket named {bucket_name}",
}
else:
return {
"status": "success",
"cluster_connected": cluster_connected,
"message": "Successfully connected to Couchbase cluster",
}
except Exception as e:
return {
"status": "error",
"cluster_connected": cluster_connected,
"error": str(e),
"message": "Failed to connect to Couchbase",
}
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.
fixed
try: | ||
bucket = ensure_bucket_connection(ctx, bucket_name) | ||
except Exception as e: | ||
logger.error(f"Error accessing bucket: {e}") | ||
raise ValueError("Tool does not have access to bucket, or bucket does not exist.") from e |
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.
This try...except
block for handling the bucket connection is duplicated in upsert_document_by_id
and delete_document_by_id
in this file, as well as in run_sql_plus_plus_query
(src/tools/query.py
) and get_scopes_and_collections_in_bucket
(src/tools/server.py
).
To improve maintainability and adhere to the Don't Repeat Yourself (DRY) principle, I recommend extracting this logic into a common helper function. This would centralize the error handling and make the tool functions cleaner and easier to maintain.
if result and (advice := result[0].get("advice")): | ||
if (advice is not None): | ||
advise_info = advice.get("adviseinfo") | ||
if ( advise_info is not None): | ||
response["current_indexes"] = advise_info.get("current_indexes", "No current indexes") | ||
response["recommended_indexes"] = advise_info.get("recommended_indexes","No index recommendations available") | ||
response["query"]=result[0].get("query","Query statement unavailable") |
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.
The nested if
statements and explicit is not None
checks make this logic for parsing the advisor's response a bit difficult to follow. The if (advice is not None):
check is redundant since the walrus operator in the outer if
already ensures advice
is a truthy value.
I suggest refactoring this to be more concise and Pythonic by flattening the conditional logic and using the walrus operator more effectively. This will improve readability.
if result and (advice := result[0].get("advice")):
if advise_info := advice.get("adviseinfo"):
response["current_indexes"] = advise_info.get("current_indexes", "No current indexes")
response["recommended_indexes"] = advise_info.get("recommended_indexes", "No index recommendations available")
response["query"] = result[0].get("query", "Query statement unavailable")
try: | ||
bucket = ensure_bucket_connection(ctx, bucket_name) | ||
except Exception as e: | ||
logger.error(f"Error accessing bucket: {e}") | ||
raise ValueError("Tool does not have access to bucket, or bucket does not exist.") from e |
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.
try: | ||
bucket = ensure_bucket_connection(ctx, bucket_name) | ||
except Exception as e: | ||
logger.error(f"Error accessing bucket: {e}") | ||
raise ValueError("Tool does not have access to bucket, or bucket does not exist.") from e |
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.