Geo Search
Many searches involve two meanings of “near”. A user searching for a “quiet café to work from” wants results that are both semantically relevant and geographically close. Qdrant handles both in a single request: the vector query ranks results by meaning, while geo conditions filter or re-rank them by location.

For example, the following request finds venues that match “quiet café to work from” within 1.5 km of a point in central Berlin:
POST /collections/venues/points/query
{
"query": {
"text": "quiet café to work from",
"model": "sentence-transformers/all-minilm-l6-v2"
},
"filter": {
"must": [
{
"key": "location",
"geo_radius": {
"center": { "lon": 13.403683, "lat": 52.520711 },
"radius": 1500.0
}
}
]
},
"limit": 5
}
from qdrant_client import QdrantClient, models
results = client.query_points(
collection_name="venues",
query=models.Document(
text="quiet café to work from",
model="sentence-transformers/all-minilm-l6-v2",
),
query_filter=models.Filter(
must=[
models.FieldCondition(
key="location",
geo_radius=models.GeoRadius(
center=models.GeoPoint(
lon=13.403683,
lat=52.520711,
),
radius=1500.0,
),
)
]
),
limit=5,
)
import { QdrantClient } from "@qdrant/js-client-rest";
const results = await client.query("venues", {
query: {
text: "quiet café to work from",
model: "sentence-transformers/all-minilm-l6-v2",
},
filter: {
must: [
{
key: "location",
geo_radius: {
center: {
lon: 13.403683,
lat: 52.520711,
},
radius: 1500.0,
},
},
],
},
limit: 5,
});
use qdrant_client::qdrant::{
Condition, Document, Filter, GeoPoint,
GeoRadius, Query, QueryPointsBuilder,
};
use qdrant_client::Qdrant;
let results = client
.query(
QueryPointsBuilder::new("venues")
.query(Query::new_nearest(Document::new(
"quiet café to work from",
"sentence-transformers/all-minilm-l6-v2",
)))
.filter(Filter::must([Condition::geo_radius(
"location",
GeoRadius {
center: Some(GeoPoint {
lon: 13.403683,
lat: 52.520711,
}),
radius: 1500.0,
},
)]))
.limit(5),
)
.await?;
import static io.qdrant.client.ConditionFactory.geoRadius;
import static io.qdrant.client.QueryFactory.nearest;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.grpc.Common.Filter;
import io.qdrant.client.grpc.Points.Document;
import io.qdrant.client.grpc.Points.QueryPoints;
var document =
Document.newBuilder()
.setText("quiet café to work from")
.setModel("sentence-transformers/all-minilm-l6-v2")
.build();
var filter =
Filter.newBuilder()
.addMust(
geoRadius(
"location", 52.520711, 13.403683, 1500.0f))
.build();
var results =
client
.queryAsync(
QueryPoints.newBuilder()
.setCollectionName("venues")
.setQuery(nearest(document))
.setFilter(filter)
.setLimit(5)
.build())
.get();
using Qdrant.Client;
using Qdrant.Client.Grpc;
using static Qdrant.Client.Grpc.Conditions;
var results = await client.QueryAsync(
collectionName: "venues",
query: new Document
{
Text = "quiet café to work from",
Model = "sentence-transformers/all-minilm-l6-v2",
},
filter: new Filter
{
Must =
{
GeoRadius(
"location", 52.520711, 13.403683, 1500.0f
),
},
},
limit: 5
);
import (
"context"
"github.com/qdrant/go-client/qdrant"
)
results, err := client.Query(
context.Background(),
&qdrant.QueryPoints{
CollectionName: "venues",
Query: qdrant.NewQueryDocument(&qdrant.Document{
Text: "quiet café to work from",
Model: "sentence-transformers/all-minilm-l6-v2",
}),
Filter: &qdrant.Filter{
Must: []*qdrant.Condition{
qdrant.NewGeoRadius(
"location", 52.520711, 13.403683, 1500.0,
),
},
},
Limit: qdrant.PtrOf(uint64(5)),
},
)
Why Location Needs Special Handling
Combining location constraints with vector search is more complex than adding a filter.
- Geographic proximity is not semantic similarity. A venue 200 meters away may be a poor semantic match, while the best match may be across town. You need to decide whether location or meaning determines which results qualify and how they are ranked.
- The same radius can produce very different result sets. A 1 km radius may cover thousands of points in a dense city center but only a handful in a rural area. The engine must handle both extremes.
- Filters can disconnect the search graph. Vector indexes such as HNSW find neighbors by walking a graph. Strict filters can exclude most nodes, leaving the remaining nodes disconnected and causing the search to miss relevant results. Filterable HNSW addresses this by adding extra edges, with the geo index contributing to the process.
For the underlying techniques, refer to the article Filtering in Vector Search.
How Geo Search Works in Qdrant
Geo search relies on three components:
- A
geopayload field. Each point stores one or more coordinates aslatandlonin its payload. - A geo payload index. The index speeds up geo filtering and helps Qdrant to plan queries. Refer to Create a Geo Index.
- Geo conditions and expressions. Conditions determine which points qualify, while expressions calculate distance-based scores. Refer to Filter by Location and Rank by Distance.
Choose an Approach
| You want to | Use | Details |
|---|---|---|
| Return only points inside an area | Use a geo filter: geo_radius, geo_bounding_box, or geo_polygon. | Filter by Location |
| Prefer nearby points without excluding distant ones | Use a formula query with geo_distance and a decay function. | Rank by Distance |
| Combine filtering and ranking | Use a geo filter to restrict the search area, and a formula query to rank the remaining points. | Combine Filtering and Ranking |
| Keep filtered search fast and accurate | Create a geo payload index before ingesting data. | Create a Geo Index |
Store Locations
Geo filters operate on payload values in the geo format: objects containing lat and lon in decimal degrees. Latitude must be between -90 and 90, and longitude between -180 and 180.
A field can also contain an array of geo objects. If a point has multiple locations, it matches when at least one location satisfies the condition.
Create a Geo Index
A geo payload index enables Qdrant to find points within a specified area without scanning every payload. Without an index, geo filters must scan the points they apply to, which can be slow on large collections.
Create a payload index on the field containing the coordinates, using the geo schema:
PUT /collections/{collection_name}/index
{
"field_name": "location",
"field_schema": "geo"
}
client.create_payload_index(
collection_name="{collection_name}",
field_name="location",
field_schema=models.PayloadSchemaType.GEO,
)
client.createPayloadIndex("{collection_name}", {
field_name: "location",
field_schema: "geo",
});
use qdrant_client::qdrant::{CreateFieldIndexCollectionBuilder, FieldType};
use qdrant_client::Qdrant;
let client = Qdrant::from_url("http://localhost:6334").build()?;
client
.create_field_index(CreateFieldIndexCollectionBuilder::new(
"{collection_name}",
"location",
FieldType::Geo,
))
.await?;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.grpc.Collections.PayloadSchemaType;
QdrantClient client =
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
client
.createPayloadIndexAsync(
"{collection_name}",
"location",
PayloadSchemaType.Geo,
null,
null,
null,
null)
.get();
using Qdrant.Client;
using Qdrant.Client.Grpc;
var client = new QdrantClient("localhost", 6334);
await client.CreatePayloadIndexAsync(
collectionName: "{collection_name}",
fieldName: "location",
schemaType: PayloadSchemaType.Geo
);
import (
"context"
"github.com/qdrant/go-client/qdrant"
)
client, err := qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
})
client.CreateFieldIndex(context.Background(), &qdrant.CreateFieldIndexCollection{
CollectionName: "{collection_name}",
FieldName: "location",
FieldType: qdrant.FieldType_FieldTypeGeo.Enum(),
})
The index supports geo_radius, geo_bounding_box, and geo_polygon conditions on that field.
Keep Filtered Search Accurate
A strict filter can leave the HNSW graph with disconnected parts, so a filtered search misses good matches. To prevent this, Qdrant automatically adds extra edges to the graph for each indexed payload field, and a geo index does the same.
For how the extra edges work, and for what to do when you combine several strict filters, refer to Filterable HNSW Index and the ACORN search algorithm.
Choose Between Full Scan and Graph Search
Qdrant selects a search strategy based on the estimated number of points matching the filter. The query planner uses payload indexes to estimate this number:
- Few matches: Qdrant performs an exact search over the matching points. The cost scales with the number of matches.
- Many matches: Qdrant traverses the HNSW graph and applies the filter during traversal.
The collection’s full_scan_threshold determines when Qdrant switches between these strategies.
For example, a radius covering a dense city center will likely use graph search, while the same radius in a rural area will likely use exact search.
Refer to Vector Index for configuration details.
Disable the Extra Edges
Available as of v1.17.0.
If a geo field is used only to filter sparse vector searches, which do not use HNSW, set enable_hnsw to false on the payload index. This reduces indexing time and memory usage.
Refer to Disable the Creation of Extra Edges for Payload Fields.
Filter by Location
A geo filter returns only points with locations inside a specified area. Like other filter conditions, you can combine it with must, should, and must_not clauses and conditions on other payload fields.
Geo filters do not affect ranking. They determine which points qualify, while the vector query determines their order. To rank results by distance, refer to Rank by Distance.
Choose a Shape
| Shape | Defined by | Use it for |
|---|---|---|
geo_radius | A center and a radius in meters | “Near me” searches |
geo_bounding_box | Two opposite corners | Map viewports and rectangular regions |
geo_polygon | An exterior ring and optional interior rings | Irregular areas such as districts, borders, or delivery zones |
For shapes without a dedicated geo condition, such as a corridor along a route, define a polygon around the area.
Radius
geo_radius matches locations within a circle defined by a center and a radius in meters. It uses the Haversine distance, which measures distance along the Earth’s surface rather than on a flat map.
{
"key": "location",
"geo_radius": {
"center": {
"lon": 13.403683,
"lat": 52.520711
},
"radius": 1000.0
}
}
models.FieldCondition(
key="location",
geo_radius=models.GeoRadius(
center=models.GeoPoint(
lon=13.403683,
lat=52.520711,
),
radius=1000.0,
),
)
{
key: 'location',
geo_radius: {
center: {
lon: 13.403683,
lat: 52.520711
},
radius: 1000.0
}
}
use qdrant_client::qdrant::{Condition, GeoPoint, GeoRadius};
Condition::geo_radius(
"location",
GeoRadius {
center: Some(GeoPoint {
lon: 13.403683,
lat: 52.520711,
}),
radius: 1000.0,
},
)
import static io.qdrant.client.ConditionFactory.geoRadius;
geoRadius("location", 52.520711, 13.403683, 1000.0f);
using static Qdrant.Client.Grpc.Conditions;
GeoRadius("location", 52.520711, 13.403683, 1000.0f);
import "github.com/qdrant/go-client/qdrant"
qdrant.NewGeoRadius("location", 52.520711, 13.403683, 1000.0)
Use a radius for searches such as “within 2 km of me”.
Bounding Box
geo_bounding_box matches locations within a rectangle aligned with latitude and longitude lines. Define the rectangle using its top_left and bottom_right corners, each specified as a lat and lon pair.
{
"key": "location",
"geo_bounding_box": {
"bottom_right": {
"lon": 13.455868,
"lat": 52.495862
},
"top_left": {
"lon": 13.403683,
"lat": 52.520711
}
}
}
models.FieldCondition(
key="location",
geo_bounding_box=models.GeoBoundingBox(
bottom_right=models.GeoPoint(
lon=13.455868,
lat=52.495862,
),
top_left=models.GeoPoint(
lon=13.403683,
lat=52.520711,
),
),
)
{
key: 'location',
geo_bounding_box: {
bottom_right: {
lon: 13.455868,
lat: 52.495862
},
top_left: {
lon: 13.403683,
lat: 52.520711
}
}
}
use qdrant_client::qdrant::{Condition, GeoBoundingBox, GeoPoint};
Condition::geo_bounding_box(
"location",
GeoBoundingBox {
bottom_right: Some(GeoPoint {
lon: 13.455868,
lat: 52.495862,
}),
top_left: Some(GeoPoint {
lon: 13.403683,
lat: 52.520711,
}),
},
)
import static io.qdrant.client.ConditionFactory.geoBoundingBox;
geoBoundingBox("location", 52.520711, 13.403683, 52.495862, 13.455868);
using static Qdrant.Client.Grpc.Conditions;
GeoBoundingBox("location", 52.520711, 13.403683, 52.495862, 13.455868);
import "github.com/qdrant/go-client/qdrant"
qdrant.NewGeoBoundingBox("location", 52.520711, 13.403683, 52.495862, 13.455868)
Bounding boxes can cross the antimeridian (180° longitude). Set top_left to a longitude greater than bottom_right, and Qdrant handles the wrapped range.
Use a bounding box for searches within a map viewport.
Polygon
Available as of v1.4.0.
geo_polygon matches locations within an arbitrary shape, such as a country, district, or delivery zone. A polygon consists of an exterior ring and optional interiors rings that define holes.
For example, to find points within a lake but exclude an island, define the lake as the exterior ring and the island as an interior ring.
{
"key": "location",
"geo_polygon": {
"exterior": {
"points": [
{ "lon": -70.0, "lat": -70.0 },
{ "lon": 60.0, "lat": -70.0 },
{ "lon": 60.0, "lat": 60.0 },
{ "lon": -70.0, "lat": 60.0 },
{ "lon": -70.0, "lat": -70.0 }
]
},
"interiors": [
{
"points": [
{ "lon": -65.0, "lat": -65.0 },
{ "lon": 0.0, "lat": -65.0 },
{ "lon": 0.0, "lat": 0.0 },
{ "lon": -65.0, "lat": 0.0 },
{ "lon": -65.0, "lat": -65.0 }
]
}
]
}
}
models.FieldCondition(
key="location",
geo_polygon=models.GeoPolygon(
exterior=models.GeoLineString(
points=[
models.GeoPoint(
lon=-70.0,
lat=-70.0,
),
models.GeoPoint(
lon=60.0,
lat=-70.0,
),
models.GeoPoint(
lon=60.0,
lat=60.0,
),
models.GeoPoint(
lon=-70.0,
lat=60.0,
),
models.GeoPoint(
lon=-70.0,
lat=-70.0,
),
]
),
interiors=[
models.GeoLineString(
points=[
models.GeoPoint(
lon=-65.0,
lat=-65.0,
),
models.GeoPoint(
lon=0.0,
lat=-65.0,
),
models.GeoPoint(
lon=0.0,
lat=0.0,
),
models.GeoPoint(
lon=-65.0,
lat=0.0,
),
models.GeoPoint(
lon=-65.0,
lat=-65.0,
),
]
)
],
),
)
{
key: "location",
geo_polygon: {
exterior: {
points: [
{
lon: -70.0,
lat: -70.0
},
{
lon: 60.0,
lat: -70.0
},
{
lon: 60.0,
lat: 60.0
},
{
lon: -70.0,
lat: 60.0
},
{
lon: -70.0,
lat: -70.0
}
]
},
interiors: [
{
points: [
{
lon: -65.0,
lat: -65.0
},
{
lon: 0,
lat: -65.0
},
{
lon: 0,
lat: 0
},
{
lon: -65.0,
lat: 0
},
{
lon: -65.0,
lat: -65.0
}
]
}
]
}
}
use qdrant_client::qdrant::{Condition, GeoLineString, GeoPoint, GeoPolygon};
Condition::geo_polygon(
"location",
GeoPolygon {
exterior: Some(GeoLineString {
points: vec![
GeoPoint {
lon: -70.0,
lat: -70.0,
},
GeoPoint {
lon: 60.0,
lat: -70.0,
},
GeoPoint {
lon: 60.0,
lat: 60.0,
},
GeoPoint {
lon: -70.0,
lat: 60.0,
},
GeoPoint {
lon: -70.0,
lat: -70.0,
},
],
}),
interiors: vec![GeoLineString {
points: vec![
GeoPoint {
lon: -65.0,
lat: -65.0,
},
GeoPoint {
lon: 0.0,
lat: -65.0,
},
GeoPoint { lon: 0.0, lat: 0.0 },
GeoPoint {
lon: -65.0,
lat: 0.0,
},
GeoPoint {
lon: -65.0,
lat: -65.0,
},
],
}],
},
)
import static io.qdrant.client.ConditionFactory.geoPolygon;
import io.qdrant.client.grpc.Common.GeoLineString;
import io.qdrant.client.grpc.Common.GeoPoint;
import java.util.List;
geoPolygon(
"location",
GeoLineString.newBuilder()
.addAllPoints(
List.of(
GeoPoint.newBuilder().setLon(-70.0).setLat(-70.0).build(),
GeoPoint.newBuilder().setLon(60.0).setLat(-70.0).build(),
GeoPoint.newBuilder().setLon(60.0).setLat(60.0).build(),
GeoPoint.newBuilder().setLon(-70.0).setLat(60.0).build(),
GeoPoint.newBuilder().setLon(-70.0).setLat(-70.0).build()))
.build(),
List.of(
GeoLineString.newBuilder()
.addAllPoints(
List.of(
GeoPoint.newBuilder().setLon(-65.0).setLat(-65.0).build(),
GeoPoint.newBuilder().setLon(0.0).setLat(-65.0).build(),
GeoPoint.newBuilder().setLon(0.0).setLat(0.0).build(),
GeoPoint.newBuilder().setLon(-65.0).setLat(0.0).build(),
GeoPoint.newBuilder().setLon(-65.0).setLat(-65.0).build()))
.build()));
using Qdrant.Client.Grpc;
using static Qdrant.Client.Grpc.Conditions;
GeoPolygon(
field: "location",
exterior: new GeoLineString
{
Points =
{
new GeoPoint { Lat = -70.0, Lon = -70.0 },
new GeoPoint { Lat = 60.0, Lon = -70.0 },
new GeoPoint { Lat = 60.0, Lon = 60.0 },
new GeoPoint { Lat = -70.0, Lon = 60.0 },
new GeoPoint { Lat = -70.0, Lon = -70.0 }
}
},
interiors: [
new()
{
Points =
{
new GeoPoint { Lat = -65.0, Lon = -65.0 },
new GeoPoint { Lat = 0.0, Lon = -65.0 },
new GeoPoint { Lat = 0.0, Lon = 0.0 },
new GeoPoint { Lat = -65.0, Lon = 0.0 },
new GeoPoint { Lat = -65.0, Lon = -65.0 }
}
}
]
);
import "github.com/qdrant/go-client/qdrant"
qdrant.NewGeoPolygon("location",
&qdrant.GeoLineString{
Points: []*qdrant.GeoPoint{
{Lat: -70, Lon: -70},
{Lat: 60, Lon: -70},
{Lat: 60, Lon: 60},
{Lat: -70, Lon: 60},
{Lat: -70, Lon: -70},
},
}, &qdrant.GeoLineString{
Points: []*qdrant.GeoPoint{
{Lat: -65, Lon: -65},
{Lat: 0, Lon: -65},
{Lat: 0, Lon: 0},
{Lat: -65, Lon: 0},
{Lat: -65, Lon: -65},
},
})
Each ring must contain at least four points, with identical first and last points to close the ring. Use a consistent clockwise or counterclockwise order within each ring.
A point matches if it falls inside the exterior ring but outside all interior rings.
Qdrant uses unprojected global coordinates (longitude and latitude in decimal degrees) and is datum-agnostic.
Combine with Other Conditions
Geo conditions work with other filter conditions. For example, to find open venues within 5 km, add a geo_radius condition and a match condition to the same must clause.
To exclude an area, add the geo condition to must_not.
Refer to Filtering for the available clauses.
Rank by Distance
A geo filter determines whether a point falls within a specified area. Geo ranking offers a more flexible approach: prioritize nearby points without excluding more relevant results that are farther away.
Use a formula query to combine vector similarity scores with distance-based scores.
Boost Points Closer to the User
Available as of v1.14.0.
The geo_distance expression calculates the Haversine distance in meters between a fixed origin and a location stored in a payload field.
Because distance has no upper bound, use a decay function to convert it into a value in the range (0, 1]. The value is 1 at the origin and decreases as distance increases. You can then add this value to the vector similarity score.
POST /collections/{collection_name}/points/query
{
"prefetch": { "query": [0.2, 0.8, ...], "limit": 50 },
"query": {
"formula": {
"sum": [
"$score",
{
"gauss_decay": {
"x": {
"geo_distance": {
"origin": { "lat": 52.504043, "lon": 13.393236 },
"to": "geo.location"
}
},
"scale": 5000 // 5km
}
}
]
},
"defaults": { "geo.location": {"lat": 48.137154, "lon": 11.576124} }
}
}
from qdrant_client import QdrantClient, models
geo_boosted = client.query_points(
collection_name="{collection_name}",
prefetch=models.Prefetch(
query=[0.1, 0.45, 0.67], # <-- dense vector
limit=50
),
query=models.FormulaQuery(
formula=models.SumExpression(sum=[
"$score",
models.GaussDecayExpression(
gauss_decay=models.DecayParamsExpression(
x=models.GeoDistance(
geo_distance=models.GeoDistanceParams(
origin=models.GeoPoint(
lat=52.504043,
lon=13.393236
), # Berlin
to="geo.location"
)
),
scale=5000 # 5km
)
)
]),
defaults={"geo.location": models.GeoPoint(lat=48.137154, lon=11.576124)} # Munich
)
)
import { QdrantClient } from "@qdrant/js-client-rest";
const client = new QdrantClient({ host: "localhost", port: 6333 });
const distance_boosted = await client.query("{collection_name}", {
prefetch: {
query: [0.1, 0.45, 0.67],
limit: 50
},
query: {
formula: {
sum: [
"$score",
{
gauss_decay: {
x: {
geo_distance: {
origin: { lat: 52.504043, lon: 13.393236 }, // Berlin
to: "geo.location"
}
},
scale: 5000 // 5km
}
}
]
},
defaults: { "geo.location": { lat: 48.137154, lon: 11.576124 } } // Munich
}
});
use qdrant_client::qdrant::{
GeoPoint, DecayParamsExpressionBuilder, Expression, FormulaBuilder, PrefetchQueryBuilder, QueryPointsBuilder,
};
use qdrant_client::Qdrant;
let client = Qdrant::from_url("http://localhost:6334").build()?;
let _geo_boosted = client.query(
QueryPointsBuilder::new("{collection_name}")
.add_prefetch(
PrefetchQueryBuilder::default()
.query(vec![0.01, 0.45, 0.67])
.limit(100u64),
)
.query(
FormulaBuilder::new(Expression::sum_with([
Expression::score(),
Expression::exp_decay(
DecayParamsExpressionBuilder::new(Expression::geo_distance_with(
// Berlin
GeoPoint { lat: 52.504043, lon: 13.393236 },
"geo.location",
))
.scale(5_000.0),
),
]))
// Munich
.add_default("geo.location", GeoPoint { lat: 48.137154, lon: 11.576124 }),
)
.limit(10),
)
.await?;
import static io.qdrant.client.ExpressionFactory.expDecay;
import static io.qdrant.client.ExpressionFactory.geoDistance;
import static io.qdrant.client.ExpressionFactory.sum;
import static io.qdrant.client.ExpressionFactory.variable;
import static io.qdrant.client.PointIdFactory.id;
import static io.qdrant.client.QueryFactory.formula;
import static io.qdrant.client.QueryFactory.nearest;
import static io.qdrant.client.ValueFactory.value;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.grpc.Common.GeoPoint;
import io.qdrant.client.grpc.Points.DecayParamsExpression;
import io.qdrant.client.grpc.Points.Formula;
import io.qdrant.client.grpc.Points.GeoDistance;
import io.qdrant.client.grpc.Points.PrefetchQuery;
import io.qdrant.client.grpc.Points.QueryPoints;
import io.qdrant.client.grpc.Points.SumExpression;
import java.util.Map;
QdrantClient client =
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
client
.queryAsync(
QueryPoints.newBuilder()
.setCollectionName("{collection_name}")
.addPrefetch(
PrefetchQuery.newBuilder()
.setQuery(nearest(0.01f, 0.45f, 0.67f))
.setLimit(100)
.build())
.setQuery(
formula(
Formula.newBuilder()
.setExpression(
sum(
SumExpression.newBuilder()
.addSum(variable("$score"))
.addSum(
expDecay(
DecayParamsExpression.newBuilder()
.setX(
geoDistance(
GeoDistance.newBuilder()
.setOrigin(
GeoPoint.newBuilder()
.setLat(52.504043)
.setLon(13.393236)
.build())
.setTo("geo.location")
.build()))
.setScale(5000)
.build()))
.build()))
.putDefaults(
"geo.location",
value(
Map.of(
"lat", value(48.137154),
"lon", value(11.576124))))
.build()))
.build())
.get();
using Qdrant.Client;
using Qdrant.Client.Grpc;
using static Qdrant.Client.Grpc.Expression;
var client = new QdrantClient("localhost", 6334);
await client.QueryAsync(
collectionName: "{collection_name}",
prefetch:
[
new PrefetchQuery { Query = new float[] { 0.01f, 0.45f, 0.67f }, Limit = 100 },
],
query: new Formula
{
Expression = new SumExpression
{
Sum =
{
"$score",
FromExpDecay(
new()
{
X = new GeoDistance
{
Origin = new GeoPoint { Lat = 52.504043, Lon = 13.393236 },
To = "geo.location",
},
Scale = 5000,
}
),
},
},
Defaults =
{
["geo.location"] = new Dictionary<string, Value>
{
["lat"] = 48.137154,
["lon"] = 11.576124,
},
},
}
);
import (
"context"
"github.com/qdrant/go-client/qdrant"
)
client, err := qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
})
client.Query(context.Background(), &qdrant.QueryPoints{
CollectionName: "{collection_name}",
Prefetch: []*qdrant.PrefetchQuery{
{
Query: qdrant.NewQuery(0.2, 0.8),
},
},
Query: qdrant.NewQueryFormula(&qdrant.Formula{
Expression: qdrant.NewExpressionSum(&qdrant.SumExpression{
Sum: []*qdrant.Expression{
qdrant.NewExpressionVariable("$score"),
qdrant.NewExpressionExpDecay(&qdrant.DecayParamsExpression{
X: qdrant.NewExpressionGeoDistance(&qdrant.GeoDistance{
Origin: &qdrant.GeoPoint{
Lat: 52.504043,
Lon: 13.393236,
},
To: "geo.location",
}),
}),
},
}),
Defaults: qdrant.NewValueMap(map[string]any{
"geo.location": map[string]any{
"lat": 48.137154,
"lon": 11.576124,
},
}),
}),
})
In this example:
prefetchretrieves candidates by vector similarity.geo_distancecalculates the distance between each candidate’sgeo.locationand the user’sorigin.gauss_decayconverts the distance into a value between 0 and 1. Thescaleparameter specifies the distance in meters at which the output equalsmidpoint(0.5 by default).sumadds the decay value to the vector score ($score).defaultsprovides a fallback location for points without one.
Refer to Decay Functions for the available functions (lin_decay, exp_decay, and gauss_decay) and their parameters.
Combine Filtering and Ranking
Filtering and ranking serve different purposes and can be combined in a single request. A geo filter restricts results to a specified area, while a formula ranks the remaining points by relevance and distance.
Add the geo condition to the query’s filter and the geo_distance expression to its formula.
For example, a delivery app can use a polygon to restrict results to its service area, then rank matching restaurants by relevance and distance.
Next Steps
- Indexing covers payload and vector indexes in general.
- Search Relevance covers formula queries and other ways to tune ranking.
- Hybrid Queries shows how to fuse several retrievers before applying a formula.