Skip to content

Commit a36ab60

Browse files
committed
Load data, vector search sections
1 parent 83a6482 commit a36ab60

File tree

12 files changed

+703
-610
lines changed

12 files changed

+703
-610
lines changed

07_Create_First_Cosmos_DB_Project/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ This section will cover how to create your first Cosmos DB project. We'll use a
44

55
## Emulator support
66

7-
Azure Cosmos DB has an emulator that can be used to develop code locally. The emulator supports the API for NoSQL and the API for MongoDB. The use of the emulator does not require an Azure subscription, nor does it incur any costs, so it is ideal for local development and testing. The Azure Cosmos DB emulator can also be utilized with unit tests in a [GitHub Actions CI workflow](https://learn.microsoft.com/azure/cosmos-db/how-to-develop-emulator?tabs=windows%2Cpython&pivots=api-mongodb#use-the-emulator-in-a-github-actions-ci-workflow).
7+
Azure Cosmos DB has an emulator that can be used to develop code locally. The emulator supports the API for NoSQL and the API for MongoDB. The use of the emulator does not require an Azure subscription, nor does it incur any costs, so it is ideal for local development and testing. The Azure Cosmos DB emulator can also be utilized with unit tests in a [GitHub Actions CI workflow](https://learn.microsoft.com/azure/cosmos-db/how-to-develop-emulator?tabs=windows%2Cpython&pivots=api-nosql#use-the-emulator-in-a-github-actions-ci-workflow).
88

99
There is not 100% feature parity between the emulator and the cloud service. Visit the [Azure Cosmos DB emulator](https://learn.microsoft.com/azure/cosmos-db/emulator) documentation for more details.
1010

1111
For Windows machines, the emulator can be installed via an installer or by using a Docker container. A Docker image is also available for Linux-based machines.
1212

13-
Learn more about the pre-requisites and installation of the emulator [here](https://learn.microsoft.com/azure/cosmos-db/how-to-develop-emulator?tabs=windows%2Cpython&pivots=api-mongodb).
13+
Learn more about the pre-requisites and installation of the emulator [here](https://learn.microsoft.com/azure/cosmos-db/how-to-develop-emulator?tabs=windows%2Cpython&pivots=api-nosql).
1414

1515
**The Azure Cosmos DB emulator does not support vector search. To complete the vector search and AI-related labs, a Azure Cosmos DB for NoSQL account in Azure is required.**
1616

1717
## Authentication
1818

19-
Authentication to Azure Cosmos DB API for Mongo DB uses a connection string. The connection string is a URL that contains the authentication information for the Azure Cosmos DB account or local emulator. The username and password used when provisioning the Azure Cosmos DB API for NoSQL service are used in the connection string when authenticating to Azure.
19+
Authentication to Azure Cosmos DB for NoSQL uses a connection string. The connection string is a URL that contains the authentication information for the Azure Cosmos DB account or local emulator.
2020

2121
### Retrieving the connection string from the Cosmos DB Emulator
2222

@@ -28,7 +28,7 @@ The splash screen or **Quickstart** section of the Cosmos DB Emulator will displ
2828

2929
Retrieve the connection string from the Azure portal by navigating to the Azure Cosmos DB account and expanding the **Settings** menu item on the left-hand side of the screen. Locate the **Primary Connection String**, and select the icon to make it visible. Copy the connection string and paste it in notepad for future reference.
3030

31-
![The Azure Cosmos DB API for NoSQL Connection strings screen displays with the copy button next to the connection string highlighted.](media/azure_connection_string.png)
31+
![The Azure Cosmos DB for NoSQL Connection strings screen displays with the copy button next to the connection string highlighted.](media/azure_connection_string.png)
3232

3333
## Lab - Create your first Cosmos DB for the NoSQL application
3434

@@ -42,7 +42,7 @@ The following concepts are covered in detail in this lab:
4242

4343
### Creating a database client
4444

45-
The `azure-cosmos` library is used to create a Cosmos DB API for NoSQL database client. The client enables both DDL (data definition language) and DML (data manipulation language) operations.
45+
The `azure-cosmos` library is used to create a Cosmos DB for NoSQL database client. The client enables both DDL (data definition language) and DML (data manipulation language) operations.
4646

4747
```python
4848
# Initialize the Cosmos DB client

08_Load_Data/README.md

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
1-
# Load data into Azure Cosmos DB API for NoSQL
1+
# Load data into Azure Cosmos DB for NoSQL
22

3-
The previous lab demonstrated how to add data to a container individually. This lab will demonstrate how to load data using bulk operations into multiple containers. This data will be used in subsequent labs to explain further the capabilities of Azure Cosmos DB API about AI.
4-
5-
When loading data, bulk operations are preferred over adding each document individually. Bulk operations involve performing multiple database operations as a batch rather than executing them simultaneously. This approach is more efficient and provides several benefits:
6-
7-
1. Performance: By issuing load operations in bulk, the lab can significantly reduce the overhead of network round-trips and database operations. This results in faster data loading and improved overall performance.
8-
9-
2. Scalability: Bulk operations allow the lab to handle large volumes of data efficiently. They can quickly process and load a substantial amount of customer, product, and sales data, enabling them to scale their operations as needed.
10-
11-
3. Atomicity: Bulk operations ensure that all database changes within a batch are treated as a single transaction. The entire batch can be rolled back if any document fails to load, maintaining data integrity and consistency.
12-
13-
4. Simplified code logic: By using bulk operations, the lab can simplify its code logic and reduce the number of database queries. This results in cleaner, more manageable code and reduces the likelihood of errors or inconsistencies.
3+
To support future labs and exercises, the Cosmic Works data must be loaded into Azure Cosmos DB for NoSQL containers. This lab will demonstrate how to load the Cosmic Works Customer, Product, and Sales data into Azure Cosmos DB for NoSQL containers.
144

155
## Lab - Load data into Azure Cosmos DB for NoSQL containers
166

17-
This lab will load the Cosmic Works Customer, Product, and Sales data into Azure Cosmos DB for NoSQL containers using bulk operations. Both the Azure Cosmos DB Emulator and Azure Cosmos DB account in Azure are supported for completion of this lab.
7+
This lab will load the Cosmic Works Customer, Product, and Sales data into Azure Cosmos DB for NoSQL containers using bulk operations.
188

199
>**Note**: It is highly recommended to use a [virtual environment](https://python.land/virtual-environments/virtualenv) for all labs.
2010
2111
Please visit the lab repository to complete [this lab](../Labs/lab_2_load_data.ipynb).
22-
23-
This lab demonstrates the use of bulk operations to load product, customer, and sales data into Azure Cosmos DB for NoSQL containers. As an example, the following code snippet inserts product data using the `bulk_write` method allowing for upsert functionality using the `UpdateOne` method:
24-
25-
```python
26-
# Add product data to database using bulkwrite and updateOne with upsert
27-
# Get cosmic works product data from github
28-
product_raw_data = "https://cosmosdbcosmicworks.blob.core.windows.net/cosmic-works-small/product.json"
29-
product_data = ProductList(items=[Product(**data) for data in requests.get(product_raw_data).json()])
30-
db.products.bulk_write([ UpdateOne({"_id": prod.id}, {"$set": prod.model_dump(by_alias=True)}, upsert=True) for prod in product_data.items])
31-
```

0 commit comments

Comments
 (0)