Skip to content
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

support Lucene's (proposed) HNSW search seeding feature #2664

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions solr/core/src/java/org/apache/solr/schema/DenseVectorField.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,22 @@ public ValueSource getValueSource(SchemaField field, QParser parser) {

public Query getKnnVectorQuery(
String fieldName, String vectorToSearch, int topK, Query filterQuery) {
return getKnnVectorQuery(fieldName, vectorToSearch, topK, filterQuery, null);
}

public Query getKnnVectorQuery(
String fieldName, String vectorToSearch, int topK, Query filterQuery, Query seedQuery) {

DenseVectorParser vectorBuilder =
getVectorBuilder(vectorToSearch, DenseVectorParser.BuilderPhase.QUERY);

switch (vectorEncoding) {
case FLOAT32:
return new KnnFloatVectorQuery(
fieldName, vectorBuilder.getFloatVector(), topK, filterQuery);
fieldName, vectorBuilder.getFloatVector(), topK, filterQuery /*, seedQuery */);
case BYTE:
return new KnnByteVectorQuery(fieldName, vectorBuilder.getByteVector(), topK, filterQuery);
return new KnnByteVectorQuery(
fieldName, vectorBuilder.getByteVector(), topK, filterQuery /*, seedQuery */);
default:
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ protected static DenseVectorField getCheckedFieldType(SchemaField schemaField) {
return (DenseVectorField) fieldType;
}

protected Query getSeedQuery() throws SolrException, SyntaxError {
return null; // TODO
}

protected Query getFilterQuery() throws SolrException, SyntaxError {

// Default behavior of FQ wrapping, and suitability of some local params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public Query parse() throws SyntaxError {
final int topK = localParams.getInt(TOP_K, DEFAULT_TOP_K);

return denseVectorType.getKnnVectorQuery(
schemaField.getName(), vectorToSearch, topK, getFilterQuery());
schemaField.getName(), vectorToSearch, topK, getFilterQuery(), getSeedQuery());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ public Query parse() throws SyntaxError {
switch (vectorEncoding) {
case FLOAT32:
return new FloatVectorSimilarityQuery(
fieldName, vectorBuilder.getFloatVector(), minTraverse, minReturn, getFilterQuery());
fieldName,
vectorBuilder.getFloatVector(),
minTraverse,
minReturn,
getFilterQuery() /*, getSeedQuery() */);
case BYTE:
return new ByteVectorSimilarityQuery(
fieldName, vectorBuilder.getByteVector(), minTraverse, minReturn, getFilterQuery());
fieldName,
vectorBuilder.getByteVector(),
minTraverse,
minReturn,
getFilterQuery() /*, getSeedQuery() */);
default:
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
Expand Down
Loading