We are excited to announce the release of the Azure Cosmos DB JavaScript SDK 4.1.0 Preview! This latest update brings several improvements, new features, and bug fixes to enhance developer experience and enable advanced data querying capabilities when working with Azure Cosmos DB. Here’s a detailed look at what’s new in this release.
New Features
Vector Search
Say hello to vector indexes, vector embedding policy, and vector queries! The new vector search feature in the Azure Cosmos DB JS SDK empowers developers to perform vector similarity searches with ease. This means you can now create and query vector embeddings, opening a world of possibilities for applications that rely on similar searches, such as recommendation engines, image recognition, and more. Read more about Vector Search in Azure Cosmos DB for NoSQL and see our Cosmos DB JS Vector Search samples. The following sample shows how to create a container with vector embedding and indexing policies.
// define vector indexing policy
const vectorEmbeddingPolicy = {
vectorEmbeddings: [
{
path: "/vector1",
dataType: VectorEmbeddingDataType.UInt8,
dimensions: 1000,
distanceFunction: VectorEmbeddingDistanceFunction.Euclidean,
},
{
path: "/vector2",
dataType: VectorEmbeddingDataType.Int8,
dimensions: 200,
distanceFunction: VectorEmbeddingDistanceFunction.DotProduct,
},
{
path: "/vector3",
dataType: VectorEmbeddingDataType.UInt8,
dimensions: 400,
distanceFunction: VectorEmbeddingDistanceFunction.Cosine,
},
],
};
// add vector indexes in Indexing Policy
const indexingPolicy = {
automatic: true,
indexingMode: "consistent",
vectorIndexes: [
{ path: "/vector1", type: VectorIndexType.Flat },
{ path: "/vector2", type: VectorIndexType.QuantizedFlat },
{ path: "/vector3", type: VectorIndexType.DiskANN },
],
};
// define and create container with vector Embedding Policy
const containerDefinition = {
id: containerId,
partitionKey: { paths: ["/id"] },
indexingPolicy: indexingPolicy,
vectorEmbeddingPolicy: vectorEmbeddingPolicy,
};
await database.containers.createIfNotExists(containerDefinition);
All Versions and Deletes Mode in Change Feed
Keeping track of every change made to your data just got easier. The new “All Versions and Deletes” mode in the change feed captures every version and every change (create, update, and delete) made to items. This feature ensures you have a complete historical record of your data changes, which is crucial for auditing, data recovery, and debugging purposes. Read more at All Versions and Deletes Mode in Change Feed and see our All Versions and Deletes Mode in Change Feed Samples
Composite Indexing
Query performance on multiple fields just got a significant boost with the introduction of composite indexing. The Cosmos DB JS SDK now supports composite indexes in the indexing policy, allowing you to optimize queries that span multiple fields. This results in faster query execution times and improves overall performance. Read more in our Composite Indexing in Azure Cosmos DB docs and see our Composite Indexing samples.
Support for MakeList and MakeSet Query Aggregators
We are excited to introduce support for the MakeList and MakeSet query aggregators in the Azure Cosmos DB JS SDK. These aggregators provide powerful ways for working with collections of data, allowing you to create lists and sets directly within your queries.
Computed Properties
Computed Properties allow you to derive values on the fly based on existing data within your documents. This feature is particularly useful for creating virtual fields that are calculated based on the values of other fields. Read more in our computed properties docs for Azure Cosmos DB and samples on computed properties.
Improvements
Bypassing Integrated Cache
We’ve added the option to bypass the integrated cache directly through the RequestOptions. This new feature empowers you with greater control over your data retrieval process, allowing you to fetch the latest data from the server when needed, bypassing the cache. Here’s a quick example of how you can use this new option.
const options: RequestOptions = {bypassIntegratedCache: true};
const response = await container.item("1").read(options);
Correlated Activity Id
To enhance troubleshooting and debugging, we’ve added a Correlated Activity Id to the header of every query request on items. This unique identifier links all requests related to a single query, even if the query involves multiple server interactions and partitions. You can access the Correlated Activity Id through the query response headers or the response.correlatedActivityId property.
Improved Samples
We’ve also overhauled our sample code to make it easier for you to find and use the examples relevant to your needs. The samples are now organized into two distinct folders for v3 and v4 of our JavaScript SDK:
- Azure Cosmos DB JS SDK v3 Samples: This folder contains examples and features up to the v3 release of the SDK.
- Azure Cosmos DB JS SDK v4 Samples: This folder includes examples and features introduced up to the v4 release.
This reorganization ensures that you can quickly locate the samples that match the SDK version you’re working with, making it simpler to implement features and follow best practices.
Bug Fixes
Split-proof Bulk API
With the 4.1.0 preview release, the Bulk API has been enhanced to be resistant to partition splits. This means that the SDK now seamlessly handles partition splits, ensuring smoother and more reliable bulk operations. Say goodbye to unexpected errors and hello to a more robust Bulk API!
Getting Started with 4.1.0 Preview
To start using the 4.1.0 preview version of the Azure Cosmos DB JavaScript SDK, you can install it via npm:
npm i @azure/cosmos
Make sure to check out the updated documentation and Azure Cosmos DB JS SDK Samples to see the new features in action.
Feedback and Contributions
We highly value the feedback from our developer community. If you encounter any issues or have suggestions for new features, please report them on our Azure Cosmos DB JS SDK GitHub Issues. Contributions are also welcome; feel free to submit pull requests to help improve the SDK.
About Azure Cosmos DB
Azure Cosmos DB is a fully managed and serverless distributed database for modern app development, with SLA-backed speed and availability, automatic and instant scalability, and support for open-source PostgreSQL, MongoDB, and Apache Cassandra. Try Azure Cosmos DB for free here. To stay in the loop on Azure Cosmos DB updates, follow us on X, YouTube, and LinkedIn.
0 comments