Skip to content

Commit fe03c71

Browse files
authored
Merge pull request #17 from Azure-Samples/copilot/add-documentation-for-deployment
Add comprehensive documentation for deployment and architecture
2 parents 61ec221 + 007684b commit fe03c71

9 files changed

+2323
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ The repository is organized as a monorepo with the following packages:
2424
- **langgraph-agent**: Core agent implementation using LangGraph
2525
- **server-api**: FastAPI server exposing the agent functionality
2626

27+
## Documentation
28+
29+
New to Azure, LangChain, monorepos, or cloud deployment? Check out our comprehensive documentation in the [**docs**](./docs) directory:
30+
31+
- 📚 [Getting Started](./docs/01-getting-started.md) - Quick setup and deployment guide
32+
- 💻 [Local Development](./docs/02-local-development.md) - Monorepo structure and npm workspaces
33+
- 🏗️ [Infrastructure & Deployment](./docs/03-infrastructure-deployment.md) - Azure Developer CLI and Bicep
34+
- 🧪 [Testing with HTTP Files](./docs/04-testing-with-http-files.md) - API testing in VS Code
35+
- 🔐 [Azure Identity Authentication](./docs/05-azure-identity-authentication.md) - Passwordless auth
36+
- 🚀 [Azure Container Apps](./docs/06-azure-container-apps.md) - Container deployment and ingress
37+
- 🔍 [Azure AI Search Vector Store](./docs/07-azure-ai-search-vector-store.md) - Vector database and indexing
38+
39+
See the [documentation index](./docs/README.md) for the complete guide.
40+
2741
## Prerequisites
2842

2943
- [Node.js](https://nodejs.org/) (v18 or later)

docs/01-getting-started.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Getting Started
2+
3+
This guide will help you get started with the Azure TypeScript LangChain sample, whether you're new to Azure, LangChain, monorepos, or cloud deployment.
4+
5+
## Overview
6+
7+
This repository demonstrates how to build an intelligent agent using TypeScript, LangChain.js, LangGraph, Azure OpenAI, and Azure AI Search to create a Retrieval Augmented Generation (RAG) application. The sample includes an HR document query system that allows users to ask questions about employee benefits and company policies.
8+
9+
## Prerequisites
10+
11+
Before you begin, ensure you have the following:
12+
13+
- **[Node.js](https://nodejs.org/)** (v18 or later)
14+
- **[npm](https://www.npmjs.com/)** (comes with Node.js)
15+
- **[Azure subscription](https://azure.microsoft.com/free/)** - Get a free account if you don't have one
16+
- **[Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli)** - For authentication and resource management
17+
- **[Azure Developer CLI (azd)](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd)** - For deployment
18+
19+
## Quick Start
20+
21+
### 1. Clone the Repository
22+
23+
```bash
24+
git clone https://github.com/Azure-Samples/azure-typescript-langchainjs.git
25+
cd azure-typescript-langchainjs
26+
```
27+
28+
### 2. Authenticate with Azure
29+
30+
```bash
31+
# Login to Azure CLI
32+
az login
33+
34+
# Configure Azure Developer CLI to use Azure CLI authentication
35+
azd config set auth.useAzCliAuth true
36+
```
37+
38+
### 3. Deploy to Azure
39+
40+
```bash
41+
# Deploy all resources and the application
42+
azd up
43+
```
44+
45+
**Important Notes:**
46+
- Choose a short environment name (7-10 lowercase letters recommended, e.g., `lang-exam`)
47+
- The deployment process takes approximately 15 minutes
48+
- This will:
49+
- Build the Docker container
50+
- Create all necessary Azure resources (OpenAI, AI Search, Container Apps, etc.)
51+
- Load the Azure AI Search index with embeddings from PDF documents
52+
- Deploy the application
53+
54+
### 4. Wait for Document Indexing
55+
56+
After deployment completes, the system will automatically index PDF documents into Azure AI Search. The sample includes **263 documents** that need to be indexed before you can use the `/answer` endpoint effectively.
57+
58+
You can check the indexing status in the deployment output, or use the Azure Portal to view your Azure AI Search service.
59+
60+
### 5. Test the API
61+
62+
Once indexing is complete, you can test the API using the URL displayed at the end of the `azd up` command:
63+
64+
```bash
65+
# Test the API (use the URL from azd up output)
66+
curl -X POST <YOUR_API_URL>/answer \
67+
-H "Content-Type: application/json" \
68+
-d '{"question": "What are the standard benefit options?"}'
69+
```
70+
71+
## Next Steps
72+
73+
- [Learn about local development](./02-local-development.md)
74+
- [Understand the CI/CD infrastructure](./03-infrastructure-deployment.md)
75+
- [Learn how to test APIs locally](./04-testing-with-http-files.md)
76+
- [Understand Azure Identity authentication](./05-azure-identity-authentication.md)
77+
78+
## Common Issues
79+
80+
### Deployment Fails
81+
82+
If deployment fails, check:
83+
- Your Azure subscription has sufficient quota for the required resources
84+
- You're deploying to a supported region (eastus2 or swedencentral)
85+
- Your environment name follows naming conventions (3-64 chars, lowercase letters, numbers, hyphens)
86+
87+
### Can't Query Documents
88+
89+
If queries return empty results:
90+
- Ensure all 263 documents are indexed (check `INDEX_DOCUMENT_COUNT` in environment variables)
91+
- Wait a few minutes after deployment for indexing to complete
92+
- Check the Azure AI Search service in the Azure Portal
93+
94+
## Additional Resources
95+
96+
- [LangChain.js Documentation](https://js.langchain.com/)
97+
- [LangGraph Documentation](https://langchain-ai.github.io/langgraphjs/)
98+
- [Azure OpenAI Service Documentation](https://learn.microsoft.com/azure/ai-services/openai/)
99+
- [Azure AI Search Documentation](https://learn.microsoft.com/azure/search/)
100+
- [Azure Container Apps Documentation](https://learn.microsoft.com/azure/container-apps/)

docs/02-local-development.md

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
# Local Development
2+
3+
This guide explains how to set up and develop this application locally using the monorepo structure with npm workspaces.
4+
5+
## Monorepo Structure
6+
7+
This repository is organized as a **monorepo** using [npm workspaces](https://docs.npmjs.com/cli/v7/using-npm/workspaces). A monorepo allows multiple related packages to be managed in a single repository, making it easier to share code and maintain consistency.
8+
9+
### Package Structure
10+
11+
The repository contains two main workspaces in the `packages-v1` directory:
12+
13+
```
14+
azure-typescript-langchainjs/
15+
├── packages-v1/
16+
│ ├── langgraph-agent/ # Core agent implementation
17+
│ └── server-api/ # Fastify API server
18+
├── package.json # Root package with workspace config
19+
└── azure.yaml # Azure deployment configuration
20+
```
21+
22+
#### langgraph-agent
23+
24+
The core agent implementation package containing:
25+
- **LangGraph agent architecture** for orchestrating AI components
26+
- **Azure OpenAI integration** for embeddings and completions
27+
- **Azure AI Search vector store** integration
28+
- **PDF document processing** and loading scripts
29+
- **Reusable utilities** for Azure credential management
30+
31+
#### server-api
32+
33+
The API server package that:
34+
- Exposes the agent functionality via REST API
35+
- Uses [Fastify](https://www.fastify.io/) web framework
36+
- Depends on the `langgraph-agent` package
37+
- Handles HTTP requests to the `/answer` endpoint
38+
39+
### Separation of Concerns
40+
41+
Each workspace has a clear responsibility:
42+
- **langgraph-agent**: Business logic, AI orchestration, data processing
43+
- **server-api**: HTTP layer, request/response handling, API contracts
44+
45+
This separation makes it easy to:
46+
- Test agent logic independently
47+
- Reuse the agent in different contexts (CLI, API, batch processing)
48+
- Scale different components independently
49+
50+
## Setting Up Local Development
51+
52+
### 1. Install Dependencies
53+
54+
From the repository root:
55+
56+
```bash
57+
# Install all dependencies for all workspaces
58+
npm install
59+
```
60+
61+
This will install dependencies for both the root project and all workspace packages.
62+
63+
### 2. Configure Environment Variables
64+
65+
**Prerequisites**: Complete the `azd up` deployment first (see [Getting Started](./01-getting-started.md)), which automatically creates the `.env` file with all necessary Azure resource information.
66+
67+
If you need to manually update environment variables, edit the `.env` file in the repository root:
68+
69+
```bash
70+
# Azure OpenAI
71+
AZURE_OPENAI_EMBEDDING_INSTANCE="your-openai-instance"
72+
AZURE_OPENAI_EMBEDDING_MODEL="text-embedding-3-small"
73+
AZURE_OPENAI_EMBEDDING_API_VERSION="2023-05-15"
74+
75+
AZURE_OPENAI_COMPLETE_INSTANCE="your-openai-instance"
76+
AZURE_OPENAI_COMPLETE_MODEL="gpt-4.1-mini"
77+
AZURE_OPENAI_COMPLETE_API_VERSION="2025-01-01-preview"
78+
AZURE_OPENAI_COMPLETE_MAX_TOKENS=1000
79+
80+
# Azure AI Search
81+
AZURE_AISEARCH_ENDPOINT="https://your-search-service.search.windows.net"
82+
AZURE_AISEARCH_INDEX_NAME="northwind"
83+
84+
# Authentication (use passwordless for local dev)
85+
SET_PASSWORDLESS=true
86+
```
87+
88+
**Note**: For local development, use passwordless authentication (`SET_PASSWORDLESS=true`) with Azure CLI login. See [Azure Identity Authentication](./05-azure-identity-authentication.md) for details.
89+
90+
### 3. Build All Packages
91+
92+
```bash
93+
# Build all workspaces
94+
npm run build
95+
```
96+
97+
This command:
98+
1. Builds all workspace packages using their individual `build` scripts
99+
2. Links packages together (via `postbuild` script)
100+
3. Creates compiled JavaScript in each package's `dist/` directory
101+
102+
## Key npm Scripts
103+
104+
The root `package.json` defines several useful scripts that work across all workspaces:
105+
106+
### Building
107+
108+
```bash
109+
# Build all packages
110+
npm run build
111+
112+
# Build specific workspace
113+
npm run build --workspace=packages-v1/langgraph-agent
114+
```
115+
116+
### Running the Server
117+
118+
```bash
119+
# Run the server in development mode (builds and runs with hot reload)
120+
npm run dev
121+
122+
# Or run production mode after building
123+
npm run build
124+
npm start
125+
```
126+
127+
The API server will start on `http://localhost:3000`.
128+
129+
### Working with Vector Data
130+
131+
**Note**: If you deployed with `azd up`, vector data is already loaded. These commands are only needed if you're setting up from scratch without using `azd up`.
132+
133+
```bash
134+
# Load PDF documents into Azure AI Search index (only needed if not using azd up)
135+
npm run load_data
136+
137+
# Test embedding generation (useful for verifying Azure OpenAI authentication)
138+
npm run embed
139+
140+
# Test LLM completion (useful for verifying Azure OpenAI authentication)
141+
npm run llm
142+
```
143+
144+
### Docker
145+
146+
```bash
147+
# Build Docker image
148+
npm run build:docker
149+
150+
# Build and run in Docker
151+
npm run start:docker
152+
```
153+
154+
### Cleanup
155+
156+
```bash
157+
# Clean build artifacts from all packages
158+
npm run clean
159+
```
160+
161+
## Development Workflow
162+
163+
### 1. Make Changes to Agent Logic
164+
165+
Edit files in `packages-v1/langgraph-agent/src/`:
166+
167+
```bash
168+
# Make changes to agent code
169+
vim packages-v1/langgraph-agent/src/graph.ts
170+
171+
# Rebuild the package
172+
npm run build --workspace=packages-v1/langgraph-agent
173+
```
174+
175+
### 2. Make Changes to API Server
176+
177+
Edit files in `packages-v1/server-api/src/`:
178+
179+
```bash
180+
# Make changes to server code
181+
vim packages-v1/server-api/src/server.ts
182+
183+
# Rebuild and run
184+
npm run dev --workspace=packages-v1/server-api
185+
```
186+
187+
### 3. Test Your Changes
188+
189+
See [Testing with HTTP Files](./04-testing-with-http-files.md) for details on testing the API.
190+
191+
## Workspace-Specific Commands
192+
193+
You can run commands in specific workspaces:
194+
195+
```bash
196+
# Run a command in langgraph-agent
197+
npm run <script> --workspace=packages-v1/langgraph-agent
198+
199+
# Run a command in server-api
200+
npm run <script> --workspace=packages-v1/server-api
201+
```
202+
203+
## TypeScript Configuration
204+
205+
Each package has its own `tsconfig.json` for TypeScript compilation:
206+
207+
- **langgraph-agent**: Configured for ES modules with Node18 target
208+
- **server-api**: Similar configuration, references langgraph-agent types
209+
210+
## Troubleshooting
211+
212+
### Build Errors
213+
214+
If you encounter build errors:
215+
216+
```bash
217+
# Clean and rebuild everything
218+
npm run clean
219+
npm install
220+
npm run build
221+
```
222+
223+
### Module Not Found Errors
224+
225+
If the server can't find the agent package:
226+
227+
```bash
228+
# Re-link packages
229+
npm run build
230+
```
231+
232+
The `postbuild` script handles linking, but you may need to run it manually.
233+
234+
### Environment Variable Issues
235+
236+
Ensure you're running commands from the repository root where the `.env` file is located. The npm scripts use `--env-file` to load environment variables.
237+
238+
## Additional Resources
239+
240+
- [npm Workspaces Documentation](https://docs.npmjs.com/cli/v7/using-npm/workspaces)
241+
- [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html)
242+
- [Node.js ES Modules](https://nodejs.org/api/esm.html)
243+
- [Fastify Documentation](https://www.fastify.io/)

0 commit comments

Comments
 (0)