apache / apache/lucene

Support for Pluggable Custom Vector Similarity Functions

Open
#14,520 1 comment 0 reactions 0 assignees View on GitHub
type:enhancement
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

### Description

Currently, Lucene supports a set of traditional vector similarity functions, including Euclidean, Dot Product, Cosine, and Maximum Inner Product.

In some vector search use cases, including our internal one, users may train their own vector similarity measurement models that outperform these built-in options in terms of relevance. These models are often more tailored to the structure and semantics of their specific data. However, Lucene does not currently provide a mechanism to plug in a custom similarity function.

I’d like to propose an enhancement to the [VectorSimilarityFunction](https://github.com/apache/lucene/blob/main/lucene/core/src/java/org/apache/lucene/index/VectorSimilarityFunction.java) enum by adding a new value: CUSTOM_SIMILARITY_FUNCTION. When selected, this option would dynamically discover a user-provided similarity implementation using Java’s Service Provider Interface (SPI) mechanism.

I’m opening this issue to gather feedback and see if this direction makes sense. We have a preliminary implementation available internally, and I’d be happy to submit a PR for review if the community is supportive.

Looking forward to your thoughts!

Contributor guide

Open the contributing guide

Research direction

Start with lucene/core/src/java/org/apache/lucene/index/VectorSimilarityFunction.java and review the proposed CUSTOM_SIMILARITY_FUNCTION value and Java Service Provider Interface approach. The issue is seeking community feedback rather than defining an implementation plan, tests, or acceptance criteria, so confirm the design direction before taking it on.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.