Skip to content

Commit

Permalink
Merge pull request #960 from MicrosoftDocs/main
Browse files Browse the repository at this point in the history
12/3/2024 PM Publish
  • Loading branch information
Taojunshen authored Dec 3, 2024
2 parents 37fdda5 + e253c01 commit 2877f06
Show file tree
Hide file tree
Showing 45 changed files with 974 additions and 838 deletions.
10 changes: 10 additions & 0 deletions articles/cosmos-db/.openpublishing.redirection.cosmos-db.json
Original file line number Diff line number Diff line change
Expand Up @@ -5970,10 +5970,20 @@
"redirect_url": "/azure/cosmos-db/table/quickstart-nodejs",
"redirect_document_id": false
},
{
"source_path_from_root": "/articles/cosmos-db/mongodb/vcore/quickstart-cross-region-replica-portal.md",
"redirect_url": "/azure/cosmos-db/mongodb/vcore/how-to-cross-region-replica-portal",
"redirect_document_id": false
},
{
"source_path_from_root": "/articles/cosmos-db/table/samples-dotnet.md",
"redirect_url": "/azure/cosmos-db/table/quickstart-dotnet",
"redirect_document_id": false
},
{
"source_path_from_root": "/articles/cosmos-db/gen-ai/quickstart-rag-chatbot.md",
"redirect_url": "/azure/cosmos-db/gen-ai/rag-chatbot",
"redirect_document_id": true
}
]
}
4 changes: 2 additions & 2 deletions articles/cosmos-db/TOC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
expanded: true
- name: AI Applications
items:
- name: Quickstart - build a RAG chatbot
href: gen-ai/quickstart-rag-chatbot.md
- name: Build a RAG chatbot
href: gen-ai/rag-chatbot.md
- name: Ingest and vectorize document files
href: gen-ai/document-ingestion.md
- name: Cosmos AI Graph - Graph RAG
Expand Down
12 changes: 9 additions & 3 deletions articles/cosmos-db/ai-advantage.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ ms.service: azure-cosmos-db
ms.custom:
- ignite-2023
ms.topic: overview
ms.date: 11/08/2023
ms.date: 12/03/2024
ms.collection:
- ce-skilling-ai-copilot
appliesto:
- ✅ NoSQL
- ✅ MongoDB
- ✅ MongoDB vCore
- ✅ Cassanda
- ✅ Gremlin
- ✅ Table
- ✅ PostgreSQL
---

# Try Azure Cosmos DB free with Azure AI Advantage

[!INCLUDE[NoSQL, MongoDB, Cassandra, Gremlin, Table](includes/appliesto-nosql-mongodb-cassandra-gremlin-table.md)]

Azure offers a full, integrated stack purpose-built for AI-powered applications. If you build your AI application stack on Azure using Azure Cosmos DB, your design can lead to solutions that get to market faster, experience lower latency, and have comprehensive built-in security.

There are many benefits when using Azure Cosmos DB and Azure AI together:
Expand Down
83 changes: 42 additions & 41 deletions articles/cosmos-db/ai-agents.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
title: AI agent
title: AI agents and solutions
titleSuffix: Azure Cosmos DB
description: Learn about key concepts for agents and step through the implementation of an AI agent memory system.
author: wmwxwa
ms.author: wangwilliam
ms.service: azure-cosmos-db
ms.custom:
- ignite-2024
ms.topic: conceptual
ms.date: 06/26/2024
ms.topic: concept-article
ms.date: 12/03/2024
ms.collection:
- ce-skilling-ai-copilot
appliesto:
- ✅ MongoDB vCore
---

# AI agent
# AI agents in Azure Cosmos DB

AI agents are designed to perform specific tasks, answer questions, and automate processes for users. These agents vary widely in complexity. They range from simple chatbots, to copilots, to advanced AI assistants in the form of digital or robotic systems that can run complex workflows autonomously.

Expand Down Expand Up @@ -241,22 +244,22 @@ The GitHub repository contains a Python project in the *loader* directory. It's

Set up your Python virtual environment in the *loader* directory by running the following command:

```python
python -m venv venv
```shell
python -m venv venv
```

Activate your environment and install dependencies in the *loader* directory:

```python
venv\Scripts\activate
python -m pip install -r requirements.txt
```shell
venv\Scripts\activate
python -m pip install -r requirements.txt
```

Create a file named *.env* in the *loader* directory, to store the following environment variables:

```python
OPENAI_API_KEY="<your OpenAI key>"
MONGO_CONNECTION_STRING="mongodb+srv:<your connection string from Azure Cosmos DB>"
```env
OPENAI_API_KEY="<your OpenAI key>"
MONGO_CONNECTION_STRING="mongodb+srv:<your connection string from Azure Cosmos DB>"
```

#### Load documents and vectors
Expand All @@ -270,7 +273,6 @@ from cosmosdbloader import CosmosDBLoader
from itinerarybuilder import ItineraryBuilder
import json


cosmosdb_loader = CosmosDBLoader(DB_Name='travel')

#read in ship data
Expand Down Expand Up @@ -301,13 +303,13 @@ collection.create_index([('name', 'text')])

Load the documents, load the vectors, and create indexes by running the following command from the *loader* directory:

```python
python main.py
```shell
python main.py
```

Here's the output of *main.py*:

```markdown
```output
--build itinerary--
--load itinerary--
--load destinations--
Expand All @@ -333,28 +335,28 @@ We used Python version 3.11.4 for the development and testing of the API.

Set up your Python virtual environment in the *api* directory:

```python
python -m venv venv
```shell
python -m venv venv
```

Activate your environment and install dependencies by using the *requirements* file in the *api* directory:

```python
venv\Scripts\activate
python -m pip install -r requirements.txt
```shell
venv\Scripts\activate
python -m pip install -r requirements.txt
```

Create a file named *.env* in the *api* directory, to store your environment variables:

```python
OPENAI_API_KEY="<your Open AI key>"
MONGO_CONNECTION_STRING="mongodb+srv:<your connection string from Azure Cosmos DB>"
```env
OPENAI_API_KEY="<your Open AI key>"
MONGO_CONNECTION_STRING="mongodb+srv:<your connection string from Azure Cosmos DB>"
```

Now that you've configured the environment and set up variables, run the following command from the *api* directory to initiate the server:

```python
python app.py
```shell
python app.py
```

The FastAPI server starts on the localhost loopback 127.0.0.1 port 8000 by default. You can access the Swagger documents by using the following localhost address: `http://127.0.0.1:8000/docs`.
Expand All @@ -369,7 +371,7 @@ Select **Try it out** for `/session/`.

:::image type="content" source="media/gen-ai/ai-agent/fastapi-get-session.png" lightbox="media/gen-ai/ai-agent/fastapi-get-session.png" alt-text="Screenshot of the use of the Get Session method in Python FastAPI, with the button for trying it out.":::

```python
```json
{
"session_id": "0505a645526f4d68a3603ef01efaab19"
}
Expand All @@ -380,9 +382,9 @@ For the AI agent, you only need to simulate a session. The stubbed-out method me
Here are the contents of *web/session.py*:

```python
@router.get("/")
def get_session():
return {'session_id':str(uuid.uuid4().hex)}
@router.get("/")
def get_session():
return {'session_id':str(uuid.uuid4().hex)}
```

### Start a conversation with the AI travel agent
Expand All @@ -395,7 +397,7 @@ Select **Try it out** for `/agent/agent_chat`.

Use this example parameter:

```python
```json
{
"input": "I want to take a relaxing vacation.",
"session_id": "0505a645526f4d68a3603ef01efaab19"
Expand All @@ -406,7 +408,7 @@ The initial execution results in a recommendation for the Tranquil Breeze Cruise

The similarity search scores appear as output from the API for debugging purposes. Here's the output after a call to `data.mongodb.travel.similarity_search()`:

```markdown
```output
0.8394561085977978
0.8086545112328692
2
Expand Down Expand Up @@ -444,7 +446,6 @@ from service import TravelAgentTools as agent_tools

load_dotenv(override=False)


chat : ChatOpenAI | None=None
agent_with_chat_history : RunnableWithMessageHistory | None=None

Expand Down Expand Up @@ -595,8 +596,8 @@ Install Node.js and the dependencies before testing the React interface.

Run the following command from the *web* directory to perform a clean installation of project dependencies. The installation might take some time.

```javascript
npm ci
```shell
npm ci
```

Next, create a file named *.env* within the *web* directory to facilitate the storage of environment variables. Include the following details in the newly created *.env* file:
Expand All @@ -605,8 +606,8 @@ Next, create a file named *.env* within the *web* directory to facilitate the st

Now, run the following command from the *web* directory to initiate the React web user interface:

```javascript
npm start
```shell
npm start
```

Running the previous command opens the React web application.
Expand All @@ -624,7 +625,7 @@ The main component serves as the central manager of the application. It acts as
Here are the contents of *main.js*:

```javascript
import React, { Component } from 'react'
import React, { Component } from 'react'
import { Stack, Link, Paper } from '@mui/material'
import TravelAgent from './TripPlanning/TravelAgent'

Expand Down Expand Up @@ -814,7 +815,7 @@ Select **Effortlessly plan your voyage** to open the travel assistant.

The chat layout component oversees the arrangement of the chat. It systematically processes the chat messages and implements the formatting specified in the `message` JSON object.

Here are the contents of *TripPlanning/ChatLayout.py*:
Here are the contents of *TripPlanning/ChatLayout.js*:

```javascript
import React from 'react'
Expand Down Expand Up @@ -843,11 +844,11 @@ export default function ChatLayout(messages) {

User prompts are on the right side and colored blue. Responses from the AI travel agent are on the left side and colored green. As the following image shows, the HTML-formatted responses are accounted for in the conversation.

:::image type="content" source="media/gen-ai/ai-agent/chat-screenshot.png" lightbox="media/gen-ai/ai-agent/chat-screenshot.png" alt-text="Screenshot of a chat.":::
:::image type="content" source="media/gen-ai/ai-agent/chat-screenshot.png" lightbox="media/gen-ai/ai-agent/chat-screenshot.png" alt-text="Screenshot of a chat with an AI agent.":::

When your AI agent is ready to go into production, you can use semantic caching to improve query performance by 80% and to reduce LLM inference and API call costs. To implement semantic caching, see [this post on the Stochastic Coder blog](https://stochasticcoder.com/2024/03/22/improve-llm-performance-using-semantic-cache-with-cosmos-db/).

:::image type="content" source="media/gen-ai/ai-agent/semantic-caching.png" lightbox="media/gen-ai/ai-agent/semantic-caching.png" alt-text="Diagram of semantic caching.":::
:::image type="content" source="media/gen-ai/ai-agent/semantic-caching.png" lightbox="media/gen-ai/ai-agent/semantic-caching.png" alt-text="Diagram of semantic caching for AI agents.":::

## Related content

Expand Down
10 changes: 7 additions & 3 deletions articles/cosmos-db/copilot-faq.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### YamlMime:FAQ
metadata:
title: |
Frequently asked questions about Microsoft Copilot for Azure in Cosmos DB (preview).
title: Frequently asked questions about Microsoft Copilot for Azure (preview).
titleSuffix: Azure Cosmos DB
description: |
Get answers to frequently asked questions about Microsoft Copilot for Azure in Cosmos DB (preview). Questions include general functionality, responsible AI, and trust categories.
author: jcodella
Expand All @@ -11,9 +11,13 @@ metadata:
ms.custom:
- ignite-2023
ms.topic: faq
ms.date: 11/10/2023
ms.date: 12/03/2024
ms.collection:
- ce-skilling-ai-copilot
appliesto:
- ✅ NoSQL
- ✅ MongoDB vCore
- ✅ PostgreSQL
title: Frequently asked questions about Microsoft Copilot for Azure in Cosmos DB (preview).
summary: |
This article provides information on general and transparency frequently asked questions about Microsoft Copilot for Azure in Cosmos DB.
Expand Down
Loading

0 comments on commit 2877f06

Please sign in to comment.