Skip to content

Commit ee0526b

Browse files
fixing relrefs
1 parent 9d4f24f commit ee0526b

File tree

22 files changed

+179
-75
lines changed

22 files changed

+179
-75
lines changed

content/commands/ft.create/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ after the SCHEMA keyword, declares which fields to index:
228228

229229
- `GEO` - Allows radius range queries against the value (point) in this attribute. The value of the attribute must be a string containing a longitude (first) and latitude separated by a comma.
230230

231-
- `VECTOR` - Allows vector queries against the value in this attribute. This requires [query dialect 2]({{< relref "/develop/interact/search-and-query/advanced-concepts/dialects#dialect-2" >}}) or above (introduced in [RediSearch v2.4](https://github.com/RediSearch/RediSearch/releases/tag/v2.4.3)). For more information, see [Vector Fields]({{< relref "/develop/interact/search-and-query/advanced-concepts/vectors" >}}).
231+
- `VECTOR` - Allows vector queries against the value in this attribute. This requires [query dialect 2]({{< relref "/develop/interact/search-and-query/advanced-concepts/dialects#dialect-2" >}}) or above (introduced in [RediSearch v2.4](https://github.com/RediSearch/RediSearch/releases/tag/v2.4.3)). For more information, see [Vector Fields]({{< relref "/develop/ai/vector-fields" >}}).
232232

233233
- `GEOSHAPE`- Allows polygon queries against the value in this attribute. The value of the attribute must follow a [WKT notation](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) list of 2D points representing the polygon edges `POLYGON((x1 y1, x2 y2, ...)` separated by a comma. A `GEOSHAPE` field type can be followed by one of the following coordinate systems:
234234
- `SPHERICAL` for Geographic longitude and latitude coordinates

content/develop/ai/index.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Redis stores and indexes vector embeddings that semantically represent unstructu
1414

1515
| Vector | RAG | RedisVL |
1616
| :-- | :-- | :-- |
17-
| {{<image filename="images/ai-cube.png" alt="AI Redis icon.">}}[Redis vector database quick start guide]({{< relref "/develop/get-started/vector-database" >}}) |{{<image filename="images/ai-brain.png" alt="AI Redis icon.">}} [Retrieval-Augmented Generation quick start guide]({{< relref "/develop/get-started/rag" >}}) | {{<image filename="images/ai-lib.png" alt="AI Redis icon.">}}[Redis vector Python client library documentation]({{< relref "/integrate/redisvl/" >}}) |
17+
| {{<image filename="images/ai-cube.png" alt="AI Redis icon.">}}[Redis vector database quick start guide]({{< relref "/develop/ai/vector-database" >}}) |{{<image filename="images/ai-brain.png" alt="AI Redis icon.">}} [Retrieval-Augmented Generation quick start guide]({{< relref "/develop/ai/rag" >}}) | {{<image filename="images/ai-lib.png" alt="AI Redis icon.">}}[Redis vector Python client library documentation]({{< relref "/integrate/redisvl/" >}}) |
1818

1919
#### Overview
2020

@@ -29,18 +29,15 @@ This page organized into a few sections depending on what you’re trying to do:
2929

3030
## How to's
3131

32-
1. [**Create a vector index**]({{< relref "develop/interact/search-and-query/advanced-concepts/vectors#create-a-vector-index" >}}): Redis maintains a secondary index over your data with a defined schema (including vector fields and metadata). Redis supports [`FLAT`]({{< relref "develop/interact/search-and-query/advanced-concepts/vectors#flat-index" >}}) and [`HNSW`]({{< relref "develop/interact/search-and-query/advanced-concepts/vectors#hnsw-index" >}}) vector index types.
33-
1. [**Store and update vectors**]({{< relref "develop/interact/search-and-query/advanced-concepts/vectors#store-and-update-vectors" >}}): Redis stores vectors and metadata in hashes or JSON objects.
34-
1. [**Search with vectors**]({{< relref "develop/interact/search-and-query/advanced-concepts/vectors#search-with-vectors" >}}): Redis supports several advanced querying strategies with vector fields including k-nearest neighbor ([KNN]({{< relref "develop/interact/search-and-query/advanced-concepts/vectors#knn-vector-search" >}})), [vector range queries]({{< relref "develop/interact/search-and-query/advanced-concepts/vectors#vector-range-queries" >}}), and [metadata filters]({{< relref "develop/interact/search-and-query/advanced-concepts/vectors#filters" >}}).
35-
1. [**Configure vector queries at runtime**]({{< relref "develop/interact/search-and-query/advanced-concepts/vectors#runtime-query-parameters" >}}). Select the best filter mode to optimize query execution.
32+
1. [**Create a vector index**]({{< relref "develop/ai/vector-fields" >}}): Redis maintains a secondary index over your data with a defined schema (including vector fields and metadata). Redis supports [`FLAT`]({{< relref "develop/ai/vector-fields#flat-index" >}}) and [`HNSW`]({{< relref "develop/ai/vector-fields#hnsw-index" >}}) vector index types.
3633

3734
## Concepts
3835

3936
Learn to perform vector search and use gateways and semantic caching in your AI/ML projects.
4037

4138
| Search | LLM memory | Semantic caching | Semantic routing | AI Gateways |
4239
| :-- | :-- | :-- | :-- | :-- |
43-
| {{<image filename="images/ai-search.png" alt="AI Redis icon.">}}[Vector search guide]({{< relref "/develop/interact/search-and-query/query/vector-search" >}}) | {{<image filename="images/ai-LLM-memory.png" alt="LLM memory icon.">}}[Store memory for LLMs](https://redis.io/blog/level-up-rag-apps-with-redis-vector-library/) | {{<image filename="images/ai-brain-2.png" alt="AI Redis icon.">}}[Semantic caching for faster, smarter LLM apps](https://redis.io/blog/what-is-semantic-caching) | {{<image filename="images/ai-semantic-routing.png" alt="Semantic routing icon.">}}[Semantic routing chooses the best tool](https://redis.io/blog/level-up-rag-apps-with-redis-vector-library/) | {{<image filename="images/ai-model.png" alt="AI Redis icon.">}}[Deploy an enhanced gateway with Redis](https://redis.io/blog/ai-gateways-what-are-they-how-can-you-deploy-an-enhanced-gateway-with-redis/) | {{<image filename="images/ai-brain-2.png" alt="AI Redis icon.">}}[Semantic caching for faster, smarter LLM apps](https://redis.io/blog/what-is-semantic-caching) |
40+
| {{<image filename="images/ai-search.png" alt="AI Redis icon.">}}[Vector search guide]({{< relref "/develop/ai/vector-search" >}}) | {{<image filename="images/ai-LLM-memory.png" alt="LLM memory icon.">}}[Store memory for LLMs](https://redis.io/blog/level-up-rag-apps-with-redis-vector-library/) | {{<image filename="images/ai-brain-2.png" alt="AI Redis icon.">}}[Semantic caching for faster, smarter LLM apps](https://redis.io/blog/what-is-semantic-caching) | {{<image filename="images/ai-semantic-routing.png" alt="Semantic routing icon.">}}[Semantic routing chooses the best tool](https://redis.io/blog/level-up-rag-apps-with-redis-vector-library/) | {{<image filename="images/ai-model.png" alt="AI Redis icon.">}}[Deploy an enhanced gateway with Redis](https://redis.io/blog/ai-gateways-what-are-they-how-can-you-deploy-an-enhanced-gateway-with-redis/) | {{<image filename="images/ai-brain-2.png" alt="AI Redis icon.">}}[Semantic caching for faster, smarter LLM apps](https://redis.io/blog/what-is-semantic-caching) |
4441

4542
## Quickstarts
4643

content/develop/ai/vector-search.md

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
categories:
3+
- docs
4+
- develop
5+
- stack
6+
- oss
7+
- rs
8+
- rc
9+
- oss
10+
- kubernetes
11+
- clients
12+
description: Query for data based on vector embeddings
13+
linkTitle: Vector search examples
14+
title: Vector search examples
15+
weight: 2
16+
---
17+
18+
This article gives you a good overview of how to perform vector search queries with Redis Stack. See the [Redis as a vector database quick start guide]({{< relref "/develop/ai/vector-database" >}}) for more information about Redis as a vector database. You can also find more detailed information about all the parameters in the [vector reference documentation]({{< relref "/develop/ai/vector-fields" >}}).
19+
20+
A vector search query on a vector field allows you to find all vectors in a vector space that are close to a given vector. You can query for the k-nearest neighbors or vectors within a given radius.
21+
22+
The examples in this article use a schema with the following fields:
23+
24+
| JSON field | Field alias | Field type | Description |
25+
| ------------------------ | ----------- | ----------- | ----------- |
26+
| `$.description` | `description` | `TEXT` | The description of a bicycle as unstructured text |
27+
| `$.description_embeddings` | `vector` | `VECTOR` | The vector that a machine learning model derived from the description text |
28+
29+
## K-neareast neighbours (KNN)
30+
31+
The Redis command [FT.SEARCH]({{< relref "commands/ft.search" >}}) takes the index name, the query string, and additional query parameters as arguments. You need to pass the number of nearest neighbors, the vector field name, and the vector's binary representation in the following way:
32+
33+
```
34+
FT.SEARCH index "(*)=>[KNN num_neighbours @field $vector]" PARAMS 2 vector "binary_data" DIALECT 2
35+
```
36+
37+
Here is a more detailed explanation of this query:
38+
39+
1. **Pre-filter**: The first expression within the round brackets is a filter. It allows you to decide which vectors should be taken into account before the vector search is performed. The expression `(*)` means that all vectors are considered.
40+
2. **Next step**: The `=>` arrow indicates that the pre-filtering happens before the vector search.
41+
3. **KNN query**: The expression `[KNN num_neighbours @field $vector]` is a parameterized query expression. A parameter name is indicated by the `$` prefix within the query string.
42+
4. **Vector binary data**: You need to use the `PARAMS` argument to substitute `$vector` with the binary representation of the vector. The value `2` indicates that `PARAMS` is followed by two arguments, the parameter name `vector` and the parameter value.
43+
5. **Dialect**: The vector search feature has been available since version two of the query dialect.
44+
45+
You can read more about the `PARAMS` argument in the [FT.SEARCH]({{< relref "commands/ft.search" >}}) command reference.
46+
47+
The following example shows you how to query for three bikes based on their description embeddings, and by using the field alias `vector`. The result is returned in ascending order based on the distance. You can see that the query only returns the fields `__vector_score` and `description`. The field `__vector_score` is present by default. Because you can have multiple vector fields in your schema, the vector score field name depends on the name of the vector field. If you change the field name `@vector` to `@foo`, the score field name changes to `__foo_score`.
48+
49+
{{< clients-example query_vector vector1 >}}
50+
FT.SEARCH idx:bikes_vss "(*)=>[KNN 3 @vector $query_vector]" PARAMS 2 "query_vector" "Z\xf8\x15:\xf23\xa1\xbfZ\x1dI>\r\xca9..." SORTBY "__vector_score" ASC RETURN 2 "__vector_score" "description" DIALECT 2
51+
{{< /clients-example >}}
52+
53+
<!-- Python query>
54+
query = (
55+
Query('(*)=>[KNN 3 @vector $query_vector]')
56+
.sort_by('__vector_score')
57+
.return_fields('__vector_score', 'description')
58+
.dialect(2)
59+
)
60+
</!-->
61+
62+
{{% alert title="Note" color="warning" %}}
63+
The binary value of the query vector is significantly shortened in the CLI example above.
64+
{{% /alert %}}
65+
66+
67+
## Radius
68+
69+
Instead of the number of nearest neighbors, you need to pass the radius along with the index name, the vector field name, and the vector's binary value:
70+
71+
```
72+
FT.SEARCH index "@field:[VECTOR_RANGE radius $vector]" PARAMS 2 vector "binary_data" DIALECT 2
73+
```
74+
75+
If you want to sort by distance, then you must yield the distance via the range query parameter `$YIELD_DISTANCE_AS`:
76+
77+
```
78+
FT.SEARCH index "@field:[VECTOR_RANGE radius $vector]=>{$YIELD_DISTANCE_AS: dist_field}" PARAMS 2 vector "binary_data" SORTBY dist_field DIALECT 2
79+
```
80+
81+
Here is a more detailed explanation of this query:
82+
83+
1. **Range query**: the syntax of a radius query is very similar to the regular range query, except for the keyword `VECTOR_RANGE`. You can also combine a vector radius query with other queries in the same way as regular range queries. See [combined queries article]({{< relref "/develop/interact/search-and-query/query/combined" >}}) for more details.
84+
2. **Additional step**: the `=>` arrow means that the range query is followed by evaluating additional parameters.
85+
3. **Range query parameters**: parameters such as `$YIELD_DISTANCE_AS` can be found in the [vectors reference documentation]({{< relref "/develop/ai/vector-fields" >}}).
86+
4. **Vector binary data**: you need to use `PARAMS` to pass the binary representation of the vector.
87+
5. **Dialect**: vector search has been available since version two of the query dialect.
88+
89+
90+
{{% alert title="Note" color="warning" %}}
91+
By default, [`FT.SEARCH`]({{< relref "commands/ft.search/" >}}) returns only the first ten results. The [range query article]({{< relref "/develop/interact/search-and-query/query/range" >}}) explains to you how to scroll through the result set.
92+
{{% /alert %}}
93+
94+
The example below shows a radius query that returns the description and the distance within a radius of `0.5`. The result is sorted by the distance.
95+
96+
{{< clients-example query_vector vector2 >}}
97+
FT.SEARCH idx:bikes_vss "@vector:[VECTOR_RANGE 0.5 $query_vector]=>{$YIELD_DISTANCE_AS: vector_dist}" PARAMS 2 "query_vector" "Z\xf8\x15:\xf23\xa1\xbfZ\x1dI>\r\xca9..." SORTBY vector_dist ASC RETURN 2 vector_dist description DIALECT 2
98+
{{< /clients-example >}}
99+
100+
<!-- Python query>
101+
query = (
102+
Query('@vector:[VECTOR_RANGE 0.5 $query_vector]=>{$YIELD_DISTANCE_AS: vector_dist}')
103+
.sort_by('vector_dist')
104+
.return_fields('vector_dist', 'description')
105+
.dialect(2)
106+
)
107+
</!-->

content/develop/clients/dotnet/vecsearch.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ weight: 3
1818
[Redis Query Engine]({{< relref "/develop/interact/search-and-query" >}})
1919
lets you index vector fields in [hash]({{< relref "/develop/data-types/hashes" >}})
2020
or [JSON]({{< relref "/develop/data-types/json" >}}) objects (see the
21-
[Vectors]({{< relref "/develop/interact/search-and-query/advanced-concepts/vectors" >}})
21+
[Vectors]({{< relref "/develop/ai/vector-fields" >}})
2222
reference page for more information).
2323
Among other things, vector fields can store *text embeddings*, which are AI-generated vector
2424
representations of the semantic information in pieces of text. The
25-
[vector distance]({{< relref "/develop/interact/search-and-query/advanced-concepts/vectors#distance-metrics" >}})
25+
[vector distance]({{< relref "/develop/ai/vector-fields#distance-metrics" >}})
2626
between two embeddings indicates how similar they are semantically. By comparing the
2727
similarity of an embedding generated from some query text with embeddings stored in hash
2828
or JSON fields, Redis can retrieve documents that closely match the query in terms
@@ -237,9 +237,9 @@ The schema in the example below includes three fields: the text content to index
237237
[tag]({{< relref "/develop/interact/search-and-query/advanced-concepts/tags" >}})
238238
field to represent the "genre" of the text, and the embedding vector generated from
239239
the original text content. The `embedding` field specifies
240-
[HNSW]({{< relref "/develop/interact/search-and-query/advanced-concepts/vectors#hnsw-index" >}})
240+
[HNSW]({{< relref "/develop/ai/vector-fields#hnsw-index" >}})
241241
indexing, the
242-
[L2]({{< relref "/develop/interact/search-and-query/advanced-concepts/vectors#distance-metrics" >}})
242+
[L2]({{< relref "/develop/ai/vector-fields#distance-metrics" >}})
243243
vector distance metric, `Float32` values to represent the vector's components,
244244
and 150 dimensions, as required by our embedding model.
245245

@@ -328,10 +328,10 @@ sorted to rank them in order of ascending distance.
328328

329329
The code below creates the query embedding using the `GetEmbedding()` method, as with
330330
the indexing, and passes it as a parameter when the query executes (see
331-
[Vector search]({{< relref "/develop/interact/search-and-query/query/vector-search" >}})
331+
[Vector search]({{< relref "/develop/ai/vector-search" >}})
332332
for more information about using query parameters with embeddings).
333333
The query is a
334-
[K nearest neighbors (KNN)]({{< relref "/develop/interact/search-and-query/advanced-concepts/vectors#knn-vector-search" >}})
334+
[K nearest neighbors (KNN)]({{< relref "/develop/ai/vector-fields#knn-vector-search" >}})
335335
search that sorts the results in order of vector distance from the query vector.
336336

337337
(As before, replace `GetEmbedding()` with `GetEmbeddingFromAzure()` if you are using
@@ -417,6 +417,6 @@ is the result that is most similar in meaning to the query text
417417
## Learn more
418418

419419
See
420-
[Vector search]({{< relref "/develop/interact/search-and-query/query/vector-search" >}})
420+
[Vector search]({{< relref "/develop/ai/vector-search" >}})
421421
for more information about the indexing options, distance metrics, and query format
422422
for vectors.

content/develop/clients/go/vecsearch.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ weight: 3
1818
[Redis Query Engine]({{< relref "/develop/interact/search-and-query" >}})
1919
lets you index vector fields in [hash]({{< relref "/develop/data-types/hashes" >}})
2020
or [JSON]({{< relref "/develop/data-types/json" >}}) objects (see the
21-
[Vectors]({{< relref "/develop/interact/search-and-query/advanced-concepts/vectors" >}})
21+
[Vectors]({{< relref "/develop/ai/vector-fields" >}})
2222
reference page for more information).
2323
Among other things, vector fields can store *text embeddings*, which are AI-generated vector
2424
representations of the semantic information in pieces of text. The
25-
[vector distance]({{< relref "/develop/interact/search-and-query/advanced-concepts/vectors#distance-metrics" >}})
25+
[vector distance]({{< relref "/develop/ai/vector-fields#distance-metrics" >}})
2626
between two embeddings indicates how similar they are semantically. By comparing the
2727
similarity of an embedding generated from some query text with embeddings stored in hash
2828
or JSON fields, Redis can retrieve documents that closely match the query in terms
@@ -131,9 +131,9 @@ three fields: the text content to index, a
131131
[tag]({{< relref "/develop/interact/search-and-query/advanced-concepts/tags" >}})
132132
field to represent the "genre" of the text, and the embedding vector generated from
133133
the original text content. The `embedding` field specifies
134-
[HNSW]({{< relref "/develop/interact/search-and-query/advanced-concepts/vectors#hnsw-index" >}})
134+
[HNSW]({{< relref "/develop/ai/vector-fields#hnsw-index" >}})
135135
indexing, the
136-
[L2]({{< relref "/develop/interact/search-and-query/advanced-concepts/vectors#distance-metrics" >}})
136+
[L2]({{< relref "/develop/ai/vector-fields#distance-metrics" >}})
137137
vector distance metric, `Float32` values to represent the vector's components,
138138
and 384 dimensions, as required by the `all-MiniLM-L6-v2` embedding model.
139139

@@ -248,7 +248,7 @@ results in order of this numeric similarity value.
248248
The code below creates the query embedding using `Embed()`, as with
249249
the indexing, and passes it as a parameter when the query executes
250250
(see
251-
[Vector search]({{< relref "/develop/interact/search-and-query/query/vector-search" >}})
251+
[Vector search]({{< relref "/develop/ai/vector-search" >}})
252252
for more information about using query parameters with embeddings).
253253

254254
```go
@@ -313,6 +313,6 @@ is the result that is most similar in meaning to the query text
313313
## Learn more
314314

315315
See
316-
[Vector search]({{< relref "/develop/interact/search-and-query/query/vector-search" >}})
316+
[Vector search]({{< relref "/develop/ai/vector-search" >}})
317317
for more information about the indexing options, distance metrics, and query format
318318
for vectors.

content/develop/clients/hiredis/issue-commands.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ redisReply *reply = redisCommand(c, "SET key:%s %s", myKeyNumber, myValue);
6767
```
6868

6969
You may need to include binary data in the command (for example, to store
70-
[vector embeddings]({{< relref "/develop/interact/search-and-query/advanced-concepts/vectors" >}})
70+
[vector embeddings]({{< relref "/develop/ai/vector-fields" >}})
7171
in fields of a [hash]({{< relref "/develop/data-types/hashes" >}})) object.
7272
To do this, use the `%b` format specifier and pass a pointer to the
7373
data buffer, followed by a `size_t` value indicating its length in bytes.

0 commit comments

Comments
 (0)