Merge pull request #1586 from qdrant/v1.14.0-review

make snippets nicer
This commit is contained in:
David Myriel
2025-04-22 19:32:42 +02:00
committed by GitHub
+61 -49
View File
@@ -53,38 +53,44 @@ Let's say you are trying to improve the search feature for a documentation site,
Your website collection can have vectors for **titles**, **paragraphs**, and **code snippet** sections of your documentation. You can create a `tag` payload field that indicates whether a point is a title, paragraph, or snippet. Then, to give more weight to titles and paragraphs, you might do something like: Your website collection can have vectors for **titles**, **paragraphs**, and **code snippet** sections of your documentation. You can create a `tag` payload field that indicates whether a point is a title, paragraph, or snippet. Then, to give more weight to titles and paragraphs, you might do something like:
``` ```text
score = score + (is_title * 0.5) + (is_paragraph * 0.25) score = score + (is_title * 0.5) + (is_paragraph * 0.25)
``` ```
**Above is just sample logic - but here is the actual Qdrant API request:** **Above is just sample logic - but here is the actual Qdrant API request:**
```bash ```http
POST /collections/{collection_name}/points/query POST /collections/{collection_name}/points/query
{ {
"prefetch": { "prefetch": {
"query": [0.2, 0.8, ...], // <-- dense vector for the query "query": [0.2, 0.8, ...], // <-- dense vector for the query
"limit": 50 "limit": 50
}, },
"query": { "query": {
"formula": { "formula": {
"sum": [ "sum": [
"$score", "$score", // Semantic score
{ {
"mult": [ "mult": [
0.5, 0.5, // weight for title
{ "key": "tag", "match": { "any": ["h1","h2","h3","h4"] } } { // Filter for title
] "key": "tag",
}, "match": { "any": ["h1","h2","h3","h4"] }
{ }
"mult": [ ]
0.25, },
{ "key": "tag", "match": { "any": ["p","li"] } } {
] "mult": [
} 0.25, // weight for paragraph
] { // Filter for paragraph
"key": "tag",
"match": { "any": ["p","li"] }
}
]
} }
]
} }
}
} }
``` ```
@@ -98,7 +104,7 @@ Now, the similarity score **doesn’t have to rely solely on cosine distance**.
**Example Query**: **Example Query**:
```bash ```http
POST /collections/{collection_name}/points/query POST /collections/{collection_name}/points/query
{ {
"prefetch": { ... }, "prefetch": { ... },
@@ -124,40 +130,46 @@ Let’s say you’re searching for a restaurant serving Currywurst. Sure, Berlin
This feature introduces a multi-objective optimization: combining semantic similarity with geographical proximity. Suppose each point has a `geo.location` payload field (latitude, longitude). You can use a `gauss_decay` function to clamp the distance into a 0–1 range and add that to your similarity score: This feature introduces a multi-objective optimization: combining semantic similarity with geographical proximity. Suppose each point has a `geo.location` payload field (latitude, longitude). You can use a `gauss_decay` function to clamp the distance into a 0–1 range and add that to your similarity score:
``` ```text
score = $score + gauss_decay(distance) score = $score + gauss_decay(distance)
``` ```
**Example Query**: **Example Query**:
```bash ```http
POST /collections/{collection_name}/points/query POST /collections/{collection_name}/points/query
{ {
"prefetch": { "prefetch": {
"query": [0.2, 0.8, ...], "query": [0.2, 0.8, ...],
"limit": 50 "limit": 50
}, },
"query": { "query": {
"formula": { "formula": {
"sum": [ "sum": [
"$score", "$score",
{ {
"gauss_decay": { "gauss_decay": {
"scale": 5000, // e.g. 5 km "scale": 5000, // e.g. 5 km
"x": { "x": {
"geo_distance": { "geo_distance": {
"origin": { "lat": 52.504043, "lon": 13.393236 }, // Berlin "origin": { // Berlin
"to": "geo.location" "lat": 52.504043,
} "lon": 13.393236
} },
} "to": "geo.location"
} }
] }
}, }
"defaults": {
"geo.location": { "lat": 48.137154, "lon": 11.576124 } // Munich
} }
]
},
"defaults": {
"geo.location": { // Munich
"lat": 48.137154,
"lon": 11.576124
}
} }
}
} }
``` ```