Skip to content

Conversation

@teetangh
Copy link
Contributor

@teetangh teetangh commented Dec 11, 2025

Summary

This PR addresses bugs, code quality issues, and extracts shared utilities to reduce code duplication.

Bug Fixes

  • Fix SQL syntax error in clear() method (missing space before WHERE)
  • Fix mutable default arguments in search methods (4 locations)
  • Add default value to prevent KeyError in query results
  • Remove redundant exception re-raising patterns (5 locations)
  • Fix type hints (**kwargs: Any, Optional vs Union)
  • Fix docstrings (remove non-existent parameters)
  • Fix missing space in error message
  • Fix line-too-long lint errors

Code Quality Improvements

  • Use logger.exception() for better error tracebacks (9 locations)
  • Fix logger anti-pattern (__file____name__)

Refactoring

  • NEW: Create langchain_couchbase/utils.py with shared validation functions:
    • check_bucket_exists() - validates bucket existence
    • check_scope_and_collection_exists() - with optimized early-exit pattern
    • validate_ttl() - validates time-to-live settings
  • Update cache.py, chat_message_histories.py, base_vector_store.py to use shared utilities
  • Remove 117 lines of duplicated code across 3 files
  • Clean up unused imports

Files Changed

  • NEW: langchain_couchbase/utils.py
  • langchain_couchbase/cache.py
  • langchain_couchbase/chat_message_histories.py
  • langchain_couchbase/vectorstores/base_vector_store.py
  • langchain_couchbase/vectorstores/query_vector_store.py
  • langchain_couchbase/vectorstores/search_vector_store.py

Testing

  • Unit tests: ✅ Passed
  • Lint (ruff): ✅ Passed

- Fix SQL syntax error in chat_message_histories.py clear() method (missing space before WHERE)
- Fix mutable default arguments in search_vector_store.py (4 locations)
- Fix logger.error() calls to use proper f-string formatting (5 locations)
- Add default value to row.pop() in query_vector_store.py to prevent KeyError
- Remove redundant exception re-raising patterns (5 locations)
- Fix type hints in cache.py (kwargs type, Union vs Optional)
- Fix docstring in base_vector_store.py (remove non-existent parameters)
- Fix missing space in error message in search_vector_store.py
- Fix line-too-long lint errors in query_vector_store.py (2 locations)
@gemini-code-assist
Copy link

Summary of Changes

Hello @teetangh, 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 focuses on a comprehensive set of bug fixes and code quality improvements across various Python files. The changes enhance the robustness of the codebase by addressing common programming pitfalls like mutable default arguments and redundant exception handling. It also improves code readability and maintainability through updated type hints, corrected docstrings, better logging practices, and adherence to linting standards. The overall aim is to make the code more reliable and easier to understand for future development.

Highlights

  • SQL Syntax Error Fix: Corrected a SQL syntax error in the clear() method of chat_message_histories.py by adding a missing space before the WHERE clause.
  • Mutable Default Argument Fixes: Addressed mutable default arguments in four locations within search_vector_store.py by changing default dictionary values from {} to None and handling initialization internally.
  • Logger Formatting Improvement: Updated five logger.error() calls to use proper f-string formatting, ensuring error messages are more informative and correctly display exceptions.
  • KeyError Prevention: Added a default value to row.pop() in query_vector_store.py to prevent potential KeyError exceptions when a key might be missing.
  • Redundant Exception Re-raising Removal: Eliminated redundant try...except Exception as e: raise e patterns in five locations across cache.py, chat_message_histories.py, base_vector_store.py, and search_vector_store.py.
  • Type Hint Corrections: Fixed type hints in cache.py, specifically adjusting kwargs type and replacing Union with Optional for better clarity and correctness.
  • Docstring Cleanup: Removed non-existent parameters from the docstring in base_vector_store.py to ensure accuracy and maintainability.
  • Error Message Clarity: Corrected a missing space in an error message within search_vector_store.py for improved readability.
  • Linting Fixes: Resolved two 'line-too-long' lint errors in query_vector_store.py by refactoring string concatenations.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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

  1. 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.

@teetangh teetangh self-assigned this Dec 11, 2025
@teetangh teetangh requested a review from nithishr December 11, 2025 08:21
gemini-code-assist[bot]

This comment was marked as resolved.

- Create langchain_couchbase/utils.py with shared validation functions:
  - check_bucket_exists()
  - check_scope_and_collection_exists() with early-exit optimization
  - validate_ttl()
- Update cache.py, chat_message_histories.py, base_vector_store.py to use utils
- Remove 117 lines of duplicated code across 3 files
- Clean up unused imports
@teetangh teetangh changed the title Fix bugs and improve code quality Fix bugs, improve code quality, and refactor shared utilities Dec 11, 2025
@teetangh teetangh marked this pull request as ready for review December 11, 2025 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants