Skip to content

Implement MagnitudeVector and add corresponding test cases - #781

Open
SYaoJun wants to merge 2 commits into
apache:masterfrom
SYaoJun:314_traversevector
Open

Implement MagnitudeVector and add corresponding test cases#781
SYaoJun wants to merge 2 commits into
apache:masterfrom
SYaoJun:314_traversevector

Conversation

@SYaoJun

@SYaoJun SYaoJun commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

fix: #773

add MagnitudeVector with match logic and unit tests

How was this PR tested?

  • Tests have Added for the changes
  • Production environment verified

@SYaoJun
SYaoJun marked this pull request as draft March 15, 2026 08:05
@SYaoJun SYaoJun changed the title add MagnitudeVector and TraversalVector Implement MagnitudeVector and add corresponding test cases Mar 22, 2026
@SYaoJun
SYaoJun marked this pull request as ready for review March 22, 2026 10:41
@SYaoJun
SYaoJun force-pushed the 314_traversevector branch from b7da49e to 5b5182e Compare March 22, 2026 10:43
@SYaoJun

SYaoJun commented Mar 25, 2026

Copy link
Copy Markdown
Contributor Author

@Leomrlin Could you please take a look at this code when you have a moment?

@Override
public double match(IVector other) {
return 0;
if (!(other instanceof MagnitudeVector)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code snippet: if (!(other instanceof MagnitudeVector)) { throw new IllegalArgumentException("Other vector must be a MagnitudeVector"); }

Problem: This can cause runtime exceptions when calling match without explicitly performing type checking when combining multiple IVectors (EmbeddingVector, KeywordVector, TraversalVector, etc.) in VectorSearch, potentially interrupting the search process.

Recommendation: For IVectors of different types, it's advisable to return 0.0 (indicating dissimilarity/not included in the scoring), or have a more explicit contract defined by the IVector interface (e.g., match supports different types and returns 0). Returning 0 is more robust and consistent with the design comment in paste ("if not same type return 0.0").

}

private double computeSimilarity(double otherMagnitude) {
if (this.magnitude == 0.0 && otherMagnitude == 0.0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the code, "magnitude" typically refers to metrics such as degree or PageRank—values ​​that are generally non-negative (≥0)—though certain centrality measures (e.g., specific eigenvector-based or normalized metrics) can be negative. The current implementation handles this using Math.abs, ensuring the calculation proceeds; however, it is advisable to either explicitly define the valid range (≥0) in the class documentation or formally document the meaning of negative values ​​if they are permitted.

Recommendation: Add Javadoc to the constructor specifying the expected range, or implement validation within the constructor (throwing an IllegalArgumentException if only non-negative values ​​are allowed).

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.

[feat] MagnitudeVector and TraversalVector not implementation

2 participants