Tenant AI Chat Solution Accelerator uses Neon Serverless Postgres on Azure to allow organisations to deploy a private chat tenant in their Azure Subscription with dedicated database per user on Neon. It is a modified version of Azure Chat Solution Accelerator by replacing Azure AI Search and Azure CosmosDB with Neon for chat data storage and search functionality.
- 📀 Database per user: Keeps chat data isolated by creating a separate database instance per user.
- 🔑 Authentication and User Management: Allows flexible login options, including OAuth providers like Google, GitHub, and Microsoft Entra ID (Azure AD).
- 🧠 AI-Powered Conversations: Chat with documents such as PDF. You can also buiild your own prompt templates.
- 💾 Chat History: Stores chat history with multiple chat threads, messages, and metadata.
- 🎨 Customizable Chat Personas: Personalizes conversations with user-defined chat personas. Manage persona settings directly from the application interface.
- 🛠️ Extensions Support: Extends chat functionalities by defining custom extensions. Store and manage extensions in the database, allowing dynamic interaction with custom workflows.
- 🎙️ Speech and Voice Support: Enables multilingual voice interactions in the chat application. Integrate Azure Speech Service for speech-to-text and text-to-speech capabilities.
- 🌐 Deployment-Ready Architecture: Fully deployable to Azure App Service with scalability for enterprise workloads.
- Private: Offers both application and database level isolation with standalone single-tenant app with single-tenant database. You can use it with your own internal data sources (PDFs, Docs) or integrate with your internal services (APIs)
- Cost-Efficient: Combines relational storage, vector storage in a single platform reduces the need for additional services, lowering costs. Scale efficiently as your user base grows while keeping costs manageable.
Service | Usage in the Project |
---|---|
Azure OpenAI | Provides models like GPT-4o for generating AI-powered conversational responses and vector embeddings for semantic search. |
Azure Key Vault | Securely stores sensitive information such as API keys, secrets, and connection strings. Used for authentication and APIs. |
Azure Blob Storage | Handles file storage and uploads for documents or media used in the chat system. Scalable solution for data backups. |
Azure App Service | Hosts the web application, REST APIs, and back-end services. Provides a managed environment to deploy and run the solution. |
Azure Monitor | Tracks and monitors application performance, errors, and logs. Helps in diagnosing issues and optimizing performance. |
Microsoft Entra ID (Azure AD) | Provides secure user authentication and authorization through OAuth2.0. Integrates with organizational identity systems. |
Azure Document Intelligence | Automates data extraction from uploaded documents using AI and OCR (Optical Character Recognition). |
Azure Speech Service | Converts speech to text and vice versa, enabling voice commands or responses in the chat system. Supports multilingual use. |
-
Node.js 18: an open-source, cross-platform JavaScript runtime environment.
-
Next.js 13: enables you to create full-stack web applications by extending the latest React features
-
NextAuth.js: configurable authentication framework for Next.js 13
-
OpenAI sdk NodeJS library that simplifies building conversational UI
-
Tailwind CSS: is a utility-first CSS framework that provides a series of predefined classes that can be used to style each element by mixing and matching
-
shadcn/ui: re-usable components built using Radix UI and Tailwind CSS.
The following high-level diagram depicts the architecture of the solution accelerator:
Clone this repository locally or fork it to your Github account.
-
Neon Account: Create a Neon account on Neon Console or via the Azure. If you have created your Azure resources using the Deployment Options in this repo, it will create automatically Neon instance on Azure.
-
Identity Provider (Optional): For local development, you do not need it. If you prefer to use an Identity Provider, follow the instructions to configure one.
- Change directory to the
src
folder - Rename the file
.env.example
to.env.local
and populate the environment variables (At least Azure OpenAI service to test out AI Chat feature). - Retrive the Neon API Key: Create create a new API Key and set it in the
.env.local
file to the value ofNEON_API_KEY
. - Install npm packages by running
npm install
- Start the app by running
npm run dev
- It automatically creates a new database for each new user on Neon database and populates schemas from
./data/schema.sql
SQL file used in the application. - Access the app on http://localhost:3000
Note
If using Basic Auth (DEV ONLY) any username you enter will create a new user id (hash of username@localhost). You can use this to simulate multiple users. Once successfully logged in, you can start creating new conversations.
- Azure account. If you're new to Azure, get an Azure account for free and you'll get some free Azure credits to get started.
- Your Azure account must have
Microsoft.Authorization/roleAssignments/write
permissions, such as Role Based Access Control Administrator, User Access Administrator, or Owner. If you don't have subscription-level permissions, you must be granted RBAC for an existing resource group and deploy to that existing group. - Your Azure account also needs
Microsoft.Resources/deployments/write
permissions on the subscription level.
You can deploy the application using one of the following options:
Important
This section will create Azure resources and deploy the solution from your local environment using the Azure Developer CLI. Note that you do not need to clone this repo to complete these steps.
- Download the Azure Developer CLI
- Run
azd auth login
and log in using your Azure account credentials. - If you have not cloned this repo, run
azd init -t https://github.com/neondatabase-labs/azure-tenant-ai-chat
. If you have cloned this repo, just run 'azd init' from the repo root directory. - Run
azd up
to provision and deploy the application
Warning
This button will only create Azure resources. You will still need to deploy the application by following the deploy to Azure section to build and deploy the application using GitHub actions.
Click on the Deploy to Azure button to deploy the Azure resources for the application.
Important
The application is protected by an identity provider and follow the steps in Add an identity provider section for adding authentication to your app.
Pricing varies per region and usage, so it isn't possible to predict exact costs for your usage. However, you can try the Azure pricing calculator - Sample Estimate for the resources below.
- Neon Serverless Postgres: Free US$0.00/month, free plan includes 10 projects, 0.5 GB storage, 190 compute hours, autoscaling up to 2 CU, read replicas, 90+ Postgres extensions including pgvector extension.
- Azure App Service: Premium V3 Tier 1 CPU core, 4 GB RAM, 250 GB Storage. Pricing per hour. Pricing
- Azure Open AI: Standard tier, ChatGPT and Embedding models. Pricing per 1K tokens used, and at least 1K tokens are used per question. Pricing
- Form Recognizer: SO (Standard) tier using pre-built layout. Pricing per document page, sample documents have 261 pages total. Pricing
- Azure Monitor: Pay-as-you-go tier. Costs based on data ingested. Pricing
To reduce costs, you can switch to free SKUs for Azure App Service and Form Recognizer by changing the parameters file under the ./infra
folder. There are some limits to consider; for example, you can have the free Form Recognizer resource only analyzes the first 2 pages of each document. You can also reduce costs associated with the Form Recognizer by reducing the number of documents you upload.
Warning
To avoid unnecessary costs, remember to destroy your provisioned resources by deleting the resource group.
Neon is a serverless, fully managed PostgreSQL database service optimized for modern applications. Neon's advanced features include autoscaling, scale-to-zero, database branching, instant point-in-time restore, and time travel queries. Neon manages the Postgres infrastructure, including database configuration, maintenance, and scaling operations, allowing you to focus on building and optimizing your applications.