Skip to content

Distance Threshold Does Not Work Without Specifying Either ID or Vector Query #291

@robert-toh

Description

@robert-toh

I'm currently working on a hybrid search and want to filter out irrelevant results using the distance threshold parameter.

According to the Typesense docs (https://typesense.org/docs/29.0/api/vector-search.html#distance-threshold) you shouldn't need either the id parameter or a vector query.

However, if I try to create a VectorQuery using that above pattern, I get the validation error below

Line 89

public VectorQuery(float[] vector, string vectorFieldName, string? id = null, int? k = null, int? flatSearchCutoff = null, Dictionary<string, string>? extraParams = null, decimal? distanceThreshold = null)
{
ArgumentNullException.ThrowIfNull(vector);
if (vector.Length > 0 && id != null)
throw new ArgumentException(
"Malformed vector query string: cannot pass both vector query and `id` parameter.");
if (vector.Length == 0 && id is null)
throw new ArgumentException("When a vector query value is empty, an `id` parameter must be present.");
if (string.IsNullOrWhiteSpace(vectorFieldName))
throw new ArgumentException(
"The vector fieldname cannot be null or whitespace.",
nameof(vectorFieldName));
_vector = vector;
VectorFieldName = vectorFieldName;
Id = id;
K = k;
DistanceThreshold = distanceThreshold;
FlatSearchCutoff = flatSearchCutoff;
ExtraParams = extraParams ?? new();
}

Is this behavior intended?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions