This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Simplify AI app development with RAG by using your own data managed by LlamaIndex, Azure Functions, and Serverless technologies. These tools manage infrastructure and scaling automatically, allowing you to focus on chatbot functionality. LlamaIndex handles the data pipeline all the way from ingestion to the streamed response.
The application flow includes:
A simple architecture of the chat app is shown in the following diagram:
This sample uses LlamaIndex to generate embeddings and store in its own vector store. LlamaIndex also provides integration with other vector stores including Azure AI Search. That integration isn't demonstrated in this sample.
The architecture of the application relies on the following services and components:
To implement a RAG (Retrieval-Augmented Generation) system using LlamaIndex, the following key steps are matched with the LlamaIndex functionality:
| Data Ingestion | Import data from sources like PDFs, APIs, or databases. | SimpleDirectoryReader |
| Chunk Documents | Breakdown large documents into smaller chunks. | SentenceSplitter |
| Vector index creation | Create a vector index for efficient similarity searches. | VectorStoreIndex |
| Recursive Retrieval (Optional) from index | Manage complex datasets with hierarchical retrieval. | |
| Convert to Query Engine | Convert the vector index into a query engine. | asQueryEngine |
| Advanced query setup (Optional) | Use agents for a multi-agent system. | |
| Implement the RAG pipeline | Define an objective function that takes user queries and retrieves relevant document chunks. | |
| Perform Retrieval | Process queries and rerank documents. | RetrieverQueryEngine, CohereRerank |
A development container environment is available with all dependencies required to complete this article. You can run the development container in GitHub Codespaces (in a browser) or locally using Visual Studio Code.
To use this article, you need the following prerequisites:
Use the following instructions to deploy a preconfigured development environment containing all required dependencies to complete this article.
GitHub Codespaces runs a development container managed by GitHub with Visual Studio Code for the Web as the user interface. For the most straightforward development environment, use GitHub Codespaces so that you have the correct developer tools and dependencies preinstalled to complete this article.
Important
All GitHub accounts can use Codespaces for up to 60 hours free each month with two core instances. For more information, see GitHub Codespaces monthly included storage and core hours.
Open in codespace.
Wait for the codespace to start. This startup process can take a few minutes.
Sign in to Azure with the Azure Developer CLI in the terminal at the bottom of the screen.
azd auth loginComplete the authentication process.
The remaining tasks in this article take place in the context of this development container.
The Dev Containers extension for Visual Studio Code requires Docker to be installed on your local machine. The extension hosts the development container locally using the Docker host with the correct developer tools and dependencies preinstalled to complete this article.
Create a new local directory on your computer for the project.
mkdir my-intelligent-app && cd my-intelligent-appOpen Visual Studio Code in that directory:
code .Open a new terminal in Visual Studio Code.
Run the following AZD command to bring the GitHub repository to your local computer.
azd init -t llama-index-javascriptOpen the Command Palette, search for and select Dev Containers: Open Folder in Container to open the project in a dev container. Wait until the dev container opens before continuing.
Sign in to Azure with the Azure Developer CLI.
azd auth loginCopy the code from the terminal and then paste it into a browser. Follow the instructions to authenticate with your Azure account.
The remaining exercises in this project take place in the context of this development container.
The sample repository contains all the code and configuration files you need to deploy the serverless chat app to Azure. The following steps walk you through the process of deploying the sample to Azure.
Important
Azure resources created in this section incur immediate costs, primarily from the Azure AI Search resource. These resources might accrue costs even if you interrupt the command before it finishes.
To provision the Azure resources and deploy the source code, run the following Azure Developer CLI command:
azd upUse the following table to answer the prompts:
| Environment name | Keep it short and lowercase. Add your name or alias. For example, john-chat. It's used as part of the resource group name. |
| Subscription | Select the subscription to create the resources in. |
| Location (for hosting) | Select a location near you from the list. |
| Location for the OpenAI model | Select a location near you from the list. If the same location is available as your first location, select that. |
Wait until app is deployed. It might take 5-10 minutes for the deployment to complete.
After successfully deploying the application, you see two URLs displayed in the terminal.
Select that URL labeled Deploying service webapp to open the chat application in a browser.
The chat app is preloaded with information about the physical standards for domestic postal mail from a PDF file catalog. You can use the chat app to ask questions about the mailing letter and packages. The following steps walk you through the process of using the chat app.
In the browser, select or enter How much does it cost to send a large package to France?.
LlamaIndex derives the answer uses the PDF file and streams the response.
The answer comes from Azure OpenAI with influence from the PDF data ingested into the LlamaIndex vector store.
To clean up resources, there are two things to address:
The Azure resources created in this article are billed to your Azure subscription. If you don't expect to need these resources in the future, delete them to avoid incurring more charges.
Run the following Azure Developer CLI command to delete the Azure resources and remove the source code:
azd down --purgeDeleting the GitHub Codespaces environment ensures that you can maximize the amount of free per-core hours entitlement you get for your account.
Important
For more information about your GitHub account's entitlements, see GitHub Codespaces monthly included storage and core hours.
Sign into the GitHub Codespaces dashboard.
Locate your currently running Codespaces sourced from the Azure-Samples/llama-index-javascript GitHub repository.
Open the context menu, ..., for the codespace and then select Delete.
You aren't necessarily required to clean up your local environment, but you can stop the running development container and return to running Visual Studio Code in the context of a local workspace.
Open the Command Palette, search for the Dev Containers commands, and then select Dev Containers: Reopen Folder Locally.
Tip
After Visual Studio Code stops the running development container, the container still exists in Docker in a stopped state. You can delete the container instance, container image, and volumes from Docker to free up more space on your local machine.
This sample repository offers troubleshooting information.
If your issue isn't addressed, log your issue to the repository's Issues.
Was this page helpful?
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?