{"id":40429083,"url":"https://github.com/neondatabase/sql-query-assistant","last_synced_at":"2026-02-17T22:02:26.619Z","repository":{"id":272256142,"uuid":"913851310","full_name":"neondatabase/sql-query-assistant","owner":"neondatabase","description":"Building an Intelligent SQL Query Assistant with Neon, .NET, Azure Functions, and Azure OpenAI service","archived":false,"fork":false,"pushed_at":"2025-01-15T16:19:43.000Z","size":176,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-29T22:53:53.891Z","etag":null,"topics":["azure","azure-functions","neondb","openai","sql"],"latest_commit_sha":null,"homepage":"https://neon.tech/blog/building-sql-query-assistant-with-dotnet-azure-functions-openai","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neondatabase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-08T13:28:15.000Z","updated_at":"2025-12-15T16:37:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"b091c9ae-550e-4357-8ef1-3f05e81c9e88","html_url":"https://github.com/neondatabase/sql-query-assistant","commit_stats":null,"previous_names":["neondatabase-labs/sql-query-assistant","neondatabase/sql-query-assistant"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/neondatabase/sql-query-assistant","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neondatabase%2Fsql-query-assistant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neondatabase%2Fsql-query-assistant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neondatabase%2Fsql-query-assistant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neondatabase%2Fsql-query-assistant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neondatabase","download_url":"https://codeload.github.com/neondatabase/sql-query-assistant/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neondatabase%2Fsql-query-assistant/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29559961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T21:50:49.831Z","status":"ssl_error","status_checked_at":"2026-02-17T21:46:15.313Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","azure-functions","neondb","openai","sql"],"created_at":"2026-01-20T16:00:28.864Z","updated_at":"2026-02-17T22:02:26.277Z","avatar_url":"https://github.com/neondatabase.png","language":"C#","readme":"# Intelligent SQL Query Assistant\n\nThis project demonstrates how to build an **Intelligent SQL Query Assistant** that enables users to interact with their **Neon** database using natural language. The assistant uses **Azure OpenAI**, **pgvector** extension in Neon, and **Retrieval-Augmented Generation (RAG)** approach to dynamically generate and execute SQL queries. Read more on [how to guide blog post](https://neon.tech/blog/building-sql-query-assistant-with-dotnet-azure-functions-openai).\n\n![SQL Query Assistant in Azure](/assets/neon-sql-query-azure-diagram.png)\n\n## Features\n\n- **Natural Language Querying**: Ask questions in plain English, and the assistant translates them into SQL queries.\n- **Vector-Based Schema Matching**: Uses embeddings and Neon's `pgvector` extension to find the most relevant database schema.\n- **Customizable APIs**:\n    - **SchemaTraining API**: Extracts the database schema, generates embeddings, and stores them in Neon.\n    - **QueryAssistant API**: Processes user queries, matches the schema, generates SQL, and executes it.\n- **Azure OpenAI Integration**: Leverages GPT models like `gpt-4` and `text-embedding-ada-002`.\n\n---\n\n## Technologies Used\n\n- **.NET Core**: Backend logic and API development.\n- **Azure Functions**: Serverless platform for API hosting.\n- **Neon**: Vector storage using the [pgvector](https://neon.tech/docs/extensions/pgvector) extension.\n- **Azure OpenAI**: For generating embeddings and SQL queries.\n- **Azure AI Foundry**: For deploying and managing AI models.\n\n---\n\n## Getting Started\n\n### Prerequisites\n\nBefore we begin, make sure you have the following:\n\n1. **Install Tools**\n    - .[NET Core SDK](https://dotnet.microsoft.com/en-us/download/dotnet)\n    - [Azure Functions Core Tools](https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=macos%2Cisolated-process%2Cnode-v4%2Cpython-v2%2Chttp-trigger%2Ccontainer-apps\u0026pivots=programming-language-csharp) installed\n    - A free [Neon account](https://console.neon.tech/signup)\n    - An [Azure account](https://azure.microsoft.com/free/) with an active subscription\n2. **Create Neon Project**\n    - Sign up for [Neon](https://neon.tech/).\n    - Create the database tables\n3. **Azure OpenAI Resource**\n    - Create an Azure OpenAI resource.\n    - Deploy models: `gpt-4` and `text-embedding-ada-002`.\n\n---\n\n### Project Structure\n\n```\nSqlQueryAssistant\n│   SqlQueryAssistant.sln\n|\n├───SqlQueryAssistant.Common\n│   │   ChatCompletionService.cs\n│\t  │\t\tEmbeddingService.cs\n│   │   SchemaService.cs\n│   │   SchemaConverter.cs\n│   │   SqlExecutorService.cs\n│   │   SchemaRetrievalService.cs\n│   │   VectorStorageService.cs\n│   └───SqlQueryAssistant.Common.csproj\n│\n├───SqlQueryAssistant.Data\n|   |   customers.sql\n|   |   schema.sql\n└───SqlQueryAssistant.Functions\n    │   host.json\n\t\t│   local.settings.json\n\t\t│   QueryAssistantFunction.cs\n    └───SqlQueryAssistant.Functions.csproj\n```\n\n## Installation\n\n### Clone the Repository\n\n```bash\ngit clone https://github.com/neondatabase-labs/sql-query-assistant.git\ncd sql-query-assistant\n```\n\n### Set Up Configuration\n\nCreate a `local.settings.json` file in the `SqlQueryAssistant.Functions` project:\n\n```json\n{\n  \"IsEncrypted\": false,\n  \"Values\": {\n    \"AzureWebJobsStorage\": \"UseDevelopmentStorage=true\",\n    \"FUNCTIONS_WORKER_RUNTIME\": \"dotnet-isolated\",\n    \"AzureOpenAI__Endpoint\": \"https://your-azure-openai-endpoint/\",\n    \"AzureOpenAI__ApiKey\": \"your-api-key\",\n    \"AzureOpenAI__EmbeddingDeploymentName\": \"text-embedding-ada-002\",\n    \"NeonDatabaseConnectionString\": \"Host=your-neon-host;Database=your-database;Username=your-username;Password=your-password;SSL Mode=Require;Trust Server Certificate=true\"\n  }\n}\n```\n\n### Install Dependencies\n\n```bash\ndotnet restore build\n```\n\n### Run the Project Locally\n\n```bash\nfunc start\n```\n\n## Usage\n\n### **SchemaTraining API**\n\n- **Endpoint**: `http://localhost:7071/api/schema-training`\n- **Method**: `POST`\n- **Description**: Trains the assistant by extracting the schema from Neon, generating embeddings, and storing them in the database.\n\n### Test with cURL:\n\n```bash\ncurl -X POST http://localhost:7071/api/schema-training\n```\n\n---\n\n### **QueryAssistant API**\n\n- **Endpoint**: `http://localhost:7071/api/query-assistant`\n- **Method**: `POST`\n- **Description**: Processes user queries, retrieves the relevant schema, generates SQL, and returns the query result.\n\n### Test with cURL:\n\n```bash\ncurl -X POST http://localhost:7071/api/query-assistant \\\n     -H \"Content-Type: application/json\" \\\n     -d '{\"Query\": \"List all customers who signed up after 2022-01-01.\"}'\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneondatabase%2Fsql-query-assistant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneondatabase%2Fsql-query-assistant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneondatabase%2Fsql-query-assistant/lists"}