Skip to content

Commit 4a2f4bf

Browse files
Merge pull request #281505 from jcodella/main
updated index guidance for nosql vectors
2 parents a08c3e2 + 2adf1bd commit 4a2f4bf

File tree

5 files changed

+53
-28
lines changed

5 files changed

+53
-28
lines changed

articles/cosmos-db/index-policy.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ Here are some rules for included and excluded paths precedence in Azure Cosmos D
116116

117117
## Vector indexes
118118

119+
> [!NOTE]
120+
> You must enroll in the [Azure Cosmos DB NoSQL Vector Index preview feature](nosql/vector-search.md#enroll-in-the-vector-search-preview-feature) to specify a vector indexing policy.>
121+
119122
**Vector** indexes increase the efficiency when performing vector searches using the `VectorDistance` system function. Vectors searches will have significantly lower latency, higher throughput, and less RU consumption when leveraging a vector index. You can specify the following types of vector index policies:
120123

121124
| Type | Description | Max dimensions |
@@ -156,14 +159,12 @@ Here's an example of an indexing policy with a vector index:
156159
}
157160
```
158161

159-
> [!NOTE]
160-
> You must enroll in the [Azure Cosmos DB NoSQL Vector Index preview feature](nosql/vector-search.md#enroll-in-the-vector-search-preview-feature) to specify a vector indexing policy.>
161-
162162
> [!IMPORTANT]
163163
> A vector indexing policy must be on the path defined in the container's vector policy. [Learn more about container vector policies](nosql/vector-search.md#container-vector-policies).
164164
> Vector indexes must also be defined at the time of Container creation and cannot be modified once created. In a future release, vector indexes will be modifiable.
165165
166-
166+
>[!IMPORTANT]
167+
> The vector path added to the "excludedPaths" section of the indexing policy to ensure optimized performance for insertion. Not adding the vector path to "excludedPaths" will result in higher RU charge and latency for vector insertions.
167168
168169
## Spatial indexes
169170

articles/cosmos-db/nosql/how-to-dotnet-vector-index-query.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,27 @@ For our example with book details, the vector policy can look like the example J
108108
Once the vector embedding paths are decided, vector indexes need to be added to the indexing policy. Currently, the vector search feature for Azure Cosmos DB for NoSQL is supported only on new containers so you need to apply the vector policy during the time of container creation and it can’t be modified later. For this example, the indexing policy would look something like this:
109109

110110
```csharp
111-
Collection<Embedding> collection = new Collection<Embedding>(embeddings);
112-
ContainerProperties properties = new ContainerProperties(id: "vector-container", partitionKeyPath: "/id")
113-
{
114-
VectorEmbeddingPolicy = new(collection),
115-
IndexingPolicy = new IndexingPolicy()
116-
{
117-
VectorIndexes = new()
118-
{
119-
new VectorIndexPath()
120-
{
121-
Path = "/vector",
122-
Type = VectorIndexType.QuantizedFlat,
123-
}
124-
}
125-
},
126-
};
111+
Collection<Embedding> collection = new Collection<Embedding>(embeddings);
112+
ContainerProperties properties = new ContainerProperties(id: "vector-container", partitionKeyPath: "/id")
113+
{
114+
VectorEmbeddingPolicy = new(collection),
115+
IndexingPolicy = new IndexingPolicy()
116+
{
117+
VectorIndexes = new()
118+
{
119+
new VectorIndexPath()
120+
{
121+
Path = "/vector",
122+
Type = VectorIndexType.QuantizedFlat,
123+
}
124+
}
125+
},
126+
};
127+
properties.IndexingPolicy.IncludedPaths.Add(new IncludedPath { Path = "/*" });
128+
properties.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/vector/*" });
127129
```
130+
>[!IMPORTANT]
131+
> The vector path added to the "excludedPaths" section of the indexing policy to ensure optimized performance for insertion. Not adding the vector path to "excludedPaths" will result in higher RU charge and latency for vector insertions.
128132
129133
> [!IMPORTANT]
130134
> Currently vector search in Azure Cosmos DB for NoSQL is supported on new containers only. You need to set both the container vector policy and any vector indexing policy during the time of container creation as it can’t be modified later. Both policies will be modifiable in a future improvement to the preview feature.

articles/cosmos-db/nosql/how-to-java-vector-index-query.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ Once the vector embedding paths are decided, vector indexes need to be added to
115115
```java
116116
IndexingPolicy indexingPolicy = new IndexingPolicy();
117117
indexingPolicy.setIndexingMode(IndexingMode.CONSISTENT);
118-
ExcludedPath excludedPath = new ExcludedPath("/*");
119-
indexingPolicy.setExcludedPaths(Collections.singletonList(excludedPath));
118+
ExcludedPath excludedPath1 = new ExcludedPath("/coverImageVector/*");
119+
ExcludedPath excludedPath2 = new ExcludedPath("/contentVector/*");
120+
indexingPolicy.setExcludedPaths(ImmutableList.of(excludedPath1, excludedPath2));
120121

121-
IncludedPath includedPath1 = new IncludedPath("/name/?");
122-
IncludedPath includedPath2 = new IncludedPath("/description/?");
123-
indexingPolicy.setIncludedPaths(ImmutableList.of(includedPath1, includedPath2));
122+
IncludedPath includedPath1 = new IncludedPath("/*");
123+
indexingPolicy.setIncludedPaths(Collections.singletonList(includedPath1));
124124

125125
// Creating vector indexes
126126
CosmosVectorIndexSpec cosmosVectorIndexSpec1 = new CosmosVectorIndexSpec();
@@ -143,6 +143,10 @@ database.createContainer(collectionDefinition).block();
143143
```
144144

145145

146+
147+
>[!IMPORTANT]
148+
> The vector path added to the "excludedPaths" section of the indexing policy to ensure optimized performance for insertion. Not adding the vector path to "excludedPaths" will result in higher RU charge and latency for vector insertions.
149+
146150
> [!IMPORTANT]
147151
> Currently vector search in Azure Cosmos DB for NoSQL is supported on new containers only. You need to set both the container vector policy and any vector indexing policy during the time of container creation as it can’t be modified later. Both policies will be modifiable in a future improvement to the preview feature.
148152

articles/cosmos-db/nosql/how-to-manage-indexing-policy.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ In addition to including or excluding paths for individual properties, you can a
105105
> You must enroll in the [Azure Cosmos DB NoSQL Vector Index preview feature](vector-search.md#enroll-in-the-vector-search-preview-feature) to use vector search in Azure Cosmos DB for NoSQL.>
106106
107107
>[!IMPORTANT]
108-
> A vector indexing policy must be on the path defined in the container's vector policy. [Learn more about container vector policies](vector-search.md#container-vector-policies).)
108+
> A vector indexing policy must be on the same path defined in the container's vector policy. [Learn more about container vector policies](vector-search.md#container-vector-policies).)
109109
110110
```json
111111
{
@@ -119,6 +119,9 @@ In addition to including or excluding paths for individual properties, you can a
119119
"excludedPaths": [
120120
{
121121
"path": "/_etag/?"
122+
},
123+
{
124+
"path": "/vector/*"
122125
}
123126
],
124127
"vectorIndexes": [
@@ -130,6 +133,10 @@ In addition to including or excluding paths for individual properties, you can a
130133
}
131134
```
132135

136+
>[!IMPORTANT]
137+
> The vector path added to the "excludedPaths" section of the indexing policy to ensure optimized performance for insertion. Not adding the vector path to "excludedPaths" will result in higher RU charge and latency for vector insertions.
138+
139+
133140
You can define the following types of vector index policies:
134141

135142
| Type | Description | Max dimensions |

articles/cosmos-db/nosql/how-to-python-vector-index-query.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ vector_embedding_policy = {
9797
            "distanceFunction": "cosine",
9898
            "dimensions": 10
9999
        }
100-
    ]
100+
]
101101
}
102102
```
103103

104+
105+
104106
## Creating a vector index in the indexing policy
105107
Once the vector embedding paths are decided, vector indexes need to be added to the indexing policy. For this example, the indexing policy would look something like this:
106108

@@ -113,7 +115,10 @@ indexing_policy = {
113115
    ],
114116
    "excludedPaths": [
115117
        {
116-
            "path": "/\"_etag\"/?"
118+
            "path": "/\"_etag\"/?",
119+
"path": "/coverImageVector/*",
120+
"path": "/contentVector/*"
121+
117122
        }
118123
    ],
119124
    "vectorIndexes": [
@@ -127,6 +132,10 @@ indexing_policy = {
127132
}
128133
```
129134

135+
>[!IMPORTANT]
136+
> The vector path added to the "excludedPaths" section of the indexing policy to ensure optimized performance for insertion. Not adding the vector path to "excludedPaths" will result in higher RU charge and latency for vector insertions.
137+
138+
130139
> [!IMPORTANT]
131140
> Currently vector search in Azure Cosmos DB for NoSQL is supported on new containers only. You need to set both the container vector policy and any vector indexing policy during the time of container creation as it can’t be modified later. Both policies will be modifiable in a future improvement to the preview feature.
132141

0 commit comments

Comments
 (0)