Skip to content

Conversation

@connermo
Copy link

Problem

OceanBase vector store was completely ignoring the score_threshold parameter during similarity search, causing it to return all top_k results regardless of their similarity scores. This was particularly problematic for the annotation feature where users set strict thresholds (e.g., score_threshold=1) but still received irrelevant low-scoring matches.

Root Cause

The search_by_vector() method in OceanBaseVector class:

  • Accepted score_threshold in **kwargs but never used it
  • Returned all results from ann_search() without filtering by score
  • This behavior was inconsistent with other vector stores (Chroma, PGVector, Qdrant, etc.)

Solution

Modified api/core/rag/datasource/vdb/oceanbase/oceanbase_vector.py to:

  1. Extract score_threshold parameter: score_threshold = float(kwargs.get("score_threshold") or 0.0)
  2. Filter results based on score: if score >= score_threshold:

This brings OceanBase behavior in line with other vector store implementations.

Changes

File: api/core/rag/datasource/vdb/oceanbase/oceanbase_vector.py

  • Line 273: Added score_threshold parameter extraction
  • Lines 290-298: Added score-based filtering logic before appending results

Testing

  • make lint - All checks passed
  • make type-check - 0 errors, 0 warnings

Impact

  • Only affects users using OceanBase as their vector store
  • Backward compatible: default threshold is 0.0 (returns all results as before)
  • Fixes annotation queries with high thresholds not working as expected

Related Issues

This fixes the issue where annotation feature with embedding model threshold set to 1 doesn't filter results properly when using OceanBase vector store.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Nov 22, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @connermo, 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 addresses a critical issue in the OceanBase vector store where the score_threshold parameter was being ignored during similarity searches, leading to the return of irrelevant results. The changes introduce proper extraction and application of the score_threshold to filter search outcomes, aligning OceanBase's behavior with other vector store implementations and significantly improving the accuracy of features like annotation.

Highlights

  • score_threshold parameter extraction: The score_threshold parameter is now correctly extracted from keyword arguments (kwargs) within the search_by_vector method, defaulting to 0.0 if not provided.
  • Score-based result filtering: Implemented logic to filter search results based on the calculated similarity score against the extracted score_threshold, ensuring that only documents meeting the specified relevance are returned.
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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 correctly implements the score_threshold filtering for OceanBase vector search, which was a missing feature. The logic for filtering results based on the score is sound. I've found a couple of areas for improvement: one is a potential unhandled exception when processing the score_threshold parameter, and the other is a performance optimization to avoid unnecessary work. Addressing these points will make the implementation more robust and efficient. Overall, a good fix that improves consistency with other vector stores.

OceanBase vector search was ignoring the score_threshold parameter, returning all top_k results regardless of their similarity scores. This caused annotation queries with high thresholds (e.g., score_threshold=1) to return low-scoring matches that should have been filtered out.

Added score_threshold parameter handling to filter results based on similarity scores, bringing OceanBase behavior in line with other vector stores (Chroma, PGVector, etc.).
@connermo connermo force-pushed the fix/oceanbase-score-threshold branch from 4d7fc8d to aadc298 Compare November 22, 2025 10:37
…tion

- Move score_threshold conversion inside try-except block to handle ValueError
- Optimize performance by checking score before parsing JSON metadata
- Only parse metadata for documents that meet the threshold criteria

Addresses Gemini Code Assist review comments.
@asukaminato0721
Copy link
Contributor

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 correctly implements score_threshold filtering for OceanBase vector searches, addressing a key issue where the parameter was ignored. The changes are logical and follow the intended behavior described. My review includes two main points. First, a medium-severity suggestion to improve the robustness of parsing the score_threshold parameter to avoid generic exceptions on invalid input. Second, a high-severity issue regarding unhandled exceptions during JSON metadata parsing, for which I've provided a code suggestion to make the process more resilient, similar to how it's handled elsewhere in the codebase. Overall, a good fix that brings OceanBase vector search in line with other implementations.

Comment on lines +291 to 298
metadata = json.loads(metadata)
metadata["score"] = score
docs.append(
Document(
page_content=_text,
metadata=metadata,
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The call to json.loads(metadata) could raise a json.JSONDecodeError if the metadata from the database is not a valid JSON string. This would cause the entire search operation to fail. It would be more robust to handle this potential error gracefully by logging a warning and using empty metadata for the document, which is consistent with the error handling in the search_by_full_text method in this file.

Suggested change
metadata = json.loads(metadata)
metadata["score"] = score
docs.append(
Document(
page_content=_text,
metadata=metadata,
)
)
try:
metadata = json.loads(metadata)
except json.JSONDecodeError:
logger.warning(f"Failed to decode metadata for document with text: '{_text[:100]}...'. Using empty metadata.")
metadata = {}
metadata["score"] = score
docs.append(
Document(
page_content=_text,
metadata=metadata,
)
)

self._hnsw_ef_search = ef_search
topk = kwargs.get("top_k", 10)
try:
score_threshold = float(kwargs.get("score_threshold") or 0.0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This line could raise a ValueError if kwargs.get("score_threshold") returns a string that cannot be converted to a float (e.g., 'abc'). While this would be caught by the outer try...except block, it would be re-raised as a generic Exception, which hides the root cause from the user. It would be better to handle this potential error more explicitly to provide a clearer error message.

Consider moving the parsing and validation of score_threshold outside of this try block to fail fast with a specific error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants