Skip to content

Samples using LangChain library with Azure SQL and SQL Server to build AI solutions on your own data

License

Notifications You must be signed in to change notification settings

Azure-Samples/azure-sql-langchain

Repository files navigation

LangChain samples with langchain_sqlserver

Get started with the langchain_sqlserver library with the following tutorials. All the tutorials works with Azure SQL or SQL Server 2025.

Note

SQL Server 2025 is available as Community Technology Preview (CTP) 1.0. To get more info on how to get the CTP, take a look here: Announcing Microsoft SQL Server 2025: Enterprise AI-ready database from ground to cloud

Note

In Azure SQL, Vector Functions are in Public Preview. Learn the details about vectors in Azure SQL here: https://aka.ms/azure-sql-vector-public-preview

LangChain Getting-Started Samples

If you're just getting started with LangChain, take a look at this article with the related sample: LangChain Integration for Vector Support for SQL-based AI applications

If you already have some familiarity with LangChain, and you are looking for samples that helps you to get started using LangChain with SQL Serve or Azure SQL, you can jump directly to the samples below.

LangChain Samples

Make sure the create an .env using .env.example as a template.

Samples on how to use the langchain_sqlserver library with SQL Server or Azure SQL as a vector store are:

  • test-1.py: Basic sample to store vectors, content and metadata into SQL Server or Azure SQL and then do simple similarity searches.
  • test-2.py: Read books reviews from a file, store it in SQL Server or Azure SQL, and then do similarity searches.

LangChain Tutorials

Build a semantic search engine

Build a semantic search engine over a PDF with document loaders, embedding models, and vector stores.

The tutorial described in the Build a semantic search engine page has been implemented in this project, but using the langchain_sqlserver library.

The file ./semantic-search.py contains the code of the tutorial. You can run it in your local environment. Make sure the create an .env using .env.example as a template.

The database used in the sample is named langchain. Make sure you have permission to create tables in the database.

Build a Retrieval Augmented Generation (RAG) App: Part 1

Introduces RAG and walks through a minimal implementation.

The tutorial described in the Build a Retrieval Augmented Generation (RAG) App: Part 1 page has been implemented in this project, but using the langchain_sqlserver library.

The file ./rag-1.py contains the code of the tutorial.

Build a Retrieval Augmented Generation (RAG) App: Part 2

Extends the implementation to accommodate conversation-style interactions and multi-step retrieval processes.

The tutorial described in the Build a Retrieval Augmented Generation (RAG) App: Part 2 page has been implemented in this project, but using the langchain_sqlserver library.

The file ./rag-2.py contains the code of the tutorial.

About

Samples using LangChain library with Azure SQL and SQL Server to build AI solutions on your own data

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages