Skip to content

Commit 8255e2b

Browse files
DOC-6186 vec database quickstart desc/diff
1 parent 2b039af commit 8255e2b

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

content/develop/get-started/vector-database.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ Create a Python virtual environment and install the following dependencies using
7676

7777
You will also need the following imports in your Python code:
7878

79-
{{< clients-example search_vss imports />}}
79+
{{< clients-example set="search_vss" step="imports" description="Foundational: Import required Python packages for vector database operations including redis, pandas, and sentence-transformers" difficulty="beginner" />}}
8080

8181
## Connect
8282

8383
Connect to Redis. By default, Redis returns binary responses. To decode them, you pass the `decode_responses` parameter set to `True`:
8484

85-
{{< clients-example search_vss connect />}}
85+
{{< clients-example set="search_vss" step="connect" description="Foundational: Connect to a Redis server with decode_responses enabled to receive decoded strings instead of bytes" difficulty="beginner" />}}
8686
<br/>
8787
{{% alert title="Tip" color="warning" %}}
8888
Instead of using a local Redis server, you can copy and paste the connection details from the Redis Cloud database configuration page. Here is an example connection string of a Cloud database that is hosted in the AWS region `us-east-1` and listens on port 16379: `redis-16379.c283.us-east-1-4.ec2.cloud.redislabs.com:16379`. The connection string has the format `host:port`. You must also copy and paste the username and password of your Cloud database. The line of code for connecting with the default user changes then to `client = redis.Redis(host="redis-16379.c283.us-east-1-4.ec2.cloud.redislabs.com", port=16379, password="your_password_here", decode_responses=True)`.
@@ -113,20 +113,20 @@ The `description` field contains free-form text descriptions of bikes and will b
113113
### 1. Fetch the demo data
114114
You need to first fetch the demo dataset as a JSON array:
115115

116-
{{< clients-example search_vss get_data />}}
116+
{{< clients-example set="search_vss" step="get_data" description="Foundational: Fetch the demo dataset as a JSON array to prepare data for vector database operations" difficulty="beginner" />}}
117117

118118
Inspect the structure of one of the bike JSON documents:
119119

120-
{{< clients-example search_vss dump_data />}}
120+
{{< clients-example set="search_vss" step="dump_data" description="Foundational: Inspect the structure of a single document from the demo dataset to understand the data format" difficulty="beginner" />}}
121121

122122
### 2. Store the demo data in Redis
123123
Now iterate over the `bikes` array to store the data as [JSON]({{< relref "/develop/data-types/json/" >}}) documents in Redis by using the [JSON.SET]({{< relref "commands/json.set/" >}}) command. The below code uses a [pipeline]({{< relref "/develop/using-commands/pipelining" >}}) to minimize the network round-trip times:
124124

125-
{{< clients-example search_vss load_data />}}
125+
{{< clients-example set="search_vss" step="load_data" description="Practical pattern: Store demo data as JSON documents in Redis using JSON.SET with pipelining to minimize network round-trips" difficulty="beginner" />}}
126126

127127
Once loaded, you can retrieve a specific attribute from one of the JSON documents in Redis using a [JSONPath](https://goessner.net/articles/JsonPath/) expression:
128128

129-
{{< clients-example search_vss get />}}
129+
{{< clients-example set="search_vss" step="get" description="Foundational: Retrieve a specific attribute from a JSON document in Redis using JSONPath expressions" difficulty="beginner" />}}
130130

131131
### 3. Select a text embedding model
132132

@@ -141,19 +141,19 @@ embedder = SentenceTransformer('msmarco-distilbert-base-v4')
141141
### 4. Generate text embeddings
142142
Iterate over all the Redis keys with the prefix `bikes:`:
143143

144-
{{< clients-example search_vss get_keys />}}
144+
{{< clients-example set="search_vss" step="get_keys" description="Foundational: Retrieve all Redis keys with a specific prefix to identify documents for processing" difficulty="beginner" />}}
145145

146146
Use the keys as input to the [JSON.MGET]({{< relref "commands/json.mget/" >}}) command, along with the `$.description` field, to collect the descriptions in a list. Then, pass the list of descriptions to the `.encode()` method:
147147

148-
{{< clients-example search_vss generate_embeddings />}}
148+
{{< clients-example set="search_vss" step="generate_embeddings" description="Create embeddings: Generate text embeddings from document descriptions using SentenceTransformers model to create vector representations" difficulty="intermediate" />}}
149149

150150
Insert the vectorized descriptions to the bike documents in Redis using the [JSON.SET]({{< relref "commands/json.set" >}}) command. The following command inserts a new field into each of the documents under the JSONPath `$.description_embeddings`. Once again, do this using a pipeline to avoid unnecessary network round-trips:
151151

152-
{{< clients-example search_vss load_embeddings />}}
152+
{{< clients-example set="search_vss" step="load_embeddings" description="Practical pattern: Insert generated vector embeddings into JSON documents using JSON.SET with pipelining for efficient batch updates" difficulty="intermediate" />}}
153153

154154
Inspect one of the updated bike documents using the [JSON.GET]({{< relref "commands/json.get" >}}) command:
155155

156-
{{< clients-example search_vss dump_example />}}
156+
{{< clients-example set="search_vss" step="dump_example" description="Foundational: Inspect an updated document containing both original data and generated vector embeddings using JSON.GET" difficulty="intermediate" />}}
157157

158158
{{% alert title="Note" color="warning" %}}
159159
When storing a vector embedding within a JSON document, the embedding is stored as a JSON array. In the example above, the array was shortened considerably for the sake of readability.
@@ -166,7 +166,7 @@ When storing a vector embedding within a JSON document, the embedding is stored
166166

167167
You must create an index to query document metadata or to perform vector searches. Use the [FT.CREATE]({{< relref "commands/ft.create" >}}) command:
168168

169-
{{< clients-example search_vss create_index >}}
169+
{{< clients-example set="search_vss" step="create_index" description="Foundational: Create an index on JSON documents with vector field using FT.CREATE with FLAT indexing and COSINE distance metric" difficulty="intermediate" >}}
170170
FT.CREATE idx:bikes_vss ON JSON
171171
PREFIX 1 bikes: SCORE 1.0
172172
SCHEMA
@@ -192,7 +192,7 @@ You can find further details about all these options in the [vector reference do
192192

193193
As soon as you execute the [FT.CREATE]({{< relref "commands/ft.create" >}}) command, the indexing process runs in the background. In a short time, all JSON documents should be indexed and ready to be queried. To validate that, you can use the [FT.INFO]({{< relref "commands/ft.info" >}}) command, which provides details and statistics about the index. Of particular interest are the number of documents successfully indexed and the number of failures:
194194

195-
{{< clients-example search_vss validate_index >}}
195+
{{< clients-example set="search_vss" step="validate_index" description="Practical pattern: Check the state and statistics of an index using FT.INFO to verify successful indexing of documents" difficulty="intermediate" >}}
196196
FT.INFO idx:bikes_vss
197197
{{< /clients-example >}}
198198

@@ -204,11 +204,11 @@ This quick start guide focuses on vector search. However, you can learn more abo
204204

205205
The following code snippet shows a list of text queries you will use to perform vector search in Redis:
206206

207-
{{< clients-example search_vss def_bulk_queries />}}
207+
{{< clients-example set="search_vss" step="def_bulk_queries" description="Foundational: Define a list of text queries to use for vector search operations" difficulty="beginner" />}}
208208

209209
First, encode each input query as a vector embedding using the same SentenceTransformers model:
210210

211-
{{< clients-example search_vss enc_bulk_queries />}}
211+
{{< clients-example set="search_vss" step="enc_bulk_queries" description="Create query embeddings: Encode text queries as vector embeddings using the same SentenceTransformers model used for document embeddings" difficulty="intermediate" />}}
212212

213213
<br/>
214214
{{% alert title="Tip" color="warning" %}}
@@ -260,7 +260,7 @@ With the template for the query in place, you can execute all queries in a loop.
260260

261261
Then, loop over the matched documents and create a list of results that can be converted into a Pandas table to visualize the results:
262262

263-
{{< clients-example search_vss define_bulk_query />}}
263+
{{< clients-example set="search_vss" step="define_bulk_query" description="Query data: Execute multiple vector search queries and format results into a Pandas table for visualization and analysis" difficulty="advanced" />}}
264264

265265
The query results show the individual queries' top three matches (our K parameter) along with the bike's id, brand, and model for each query.
266266

@@ -270,7 +270,7 @@ For example, for the query "Best Mountain bikes for kids", the highest similarit
270270
271271
From the description, this bike is an excellent match for younger children, and the embeddings accurately captured the semantics of the description.
272272

273-
{{< clients-example search_vss run_knn_query />}}
273+
{{< clients-example set="search_vss" step="run_knn_query" description="Semantic search: Execute K-nearest neighbors vector search using FT.SEARCH with KNN algorithm to find semantically similar documents" difficulty="advanced" />}}
274274

275275
| query | score | id | brand | model | description |
276276
| :--- | :--- | :--- | :--- | :--- | :--- |

0 commit comments

Comments
 (0)