![]() |
VOOZH | about |
dotnet add package LangChain.Utilities.Postgres --version 0.17.1
NuGet\Install-Package LangChain.Utilities.Postgres -Version 0.17.1
<PackageReference Include="LangChain.Utilities.Postgres" Version="0.17.1" />
<PackageVersion Include="LangChain.Utilities.Postgres" Version="0.17.1" />Directory.Packages.props
<PackageReference Include="LangChain.Utilities.Postgres" />Project file
paket add LangChain.Utilities.Postgres --version 0.17.1
#r "nuget: LangChain.Utilities.Postgres, 0.17.1"
#:package LangChain.Utilities.Postgres@0.17.1
#addin nuget:?package=LangChain.Utilities.Postgres&version=0.17.1Install as a Cake Addin
#tool nuget:?package=LangChain.Utilities.Postgres&version=0.17.1Install as a Cake Tool
š Nuget package
š dotnet
š License: MIT
š Discord
ā” Building applications with LLMs through composability ā”
C# implementation of LangChain. We try to be as close to the original as possible in terms of abstractions, but are open to new entities.
While the SemanticKernel is good and we will use it wherever possible, we believe that it has many limitations and based on Microsoft technologies. We proceed from the position of the maximum choice of available options and are open to using third-party libraries within individual implementations.
I want to note:
You can use our wiki to get started: https://tryagi.github.io/LangChain/
If the wiki contains unupdated code, you can always take a look at
Also see for example usage or .
// Price to run from zero(create embeddings and request to LLM): 0,015$
// Price to re-run if database is exists: 0,0004$
// Dependencies: LangChain, LangChain.Databases.Sqlite, LangChain.DocumentLoaders.Pdf
// Initialize models
var provider = new OpenAiProvider(
Environment.GetEnvironmentVariable("OPENAI_API_KEY") ??
throw new InconclusiveException("OPENAI_API_KEY is not set"));
var llm = new OpenAiLatestFastChatModel(provider);
var embeddingModel = new TextEmbeddingV3SmallModel(provider);
// Create vector database from Harry Potter book pdf
using var vectorDatabase = new SqLiteVectorDatabase(dataSource: "vectors.db");
var vectorCollection = await vectorDatabase.AddDocumentsFromAsync<PdfPigPdfLoader>(
embeddingModel, // Used to convert text to embeddings
dimensions: 1536, // Should be 1536 for TextEmbeddingV3SmallModel
dataSource: DataSource.FromUrl("https://canonburyprimaryschool.co.uk/wp-content/uploads/2016/01/Joanne-K.-Rowling-Harry-Potter-Book-1-Harry-Potter-and-the-Philosophers-Stone-EnglishOnlineClub.com_.pdf"),
collectionName: "harrypotter", // Can be omitted, use if you want to have multiple collections
textSplitter: null); // Default is CharacterTextSplitter(ChunkSize = 4000, ChunkOverlap = 200)
// Now we have two ways: use the async methods or use the chains
// 1. Async methods
// Find similar documents for the question
const string question = "Who was drinking a unicorn blood?";
var similarDocuments = await vectorCollection.GetSimilarDocuments(embeddingModel, question, amount: 5);
// Use similar documents and LLM to answer the question
var answer = await llm.GenerateAsync(
$"""
Use the following pieces of context to answer the question at the end.
If the answer is not in context then just say that you don't know, don't try to make up an answer.
Keep the answer as short as possible.
{similarDocuments.AsString()}
Question: {question}
Helpful Answer:
""");
Console.WriteLine($"LLM answer: {answer}"); // The cloaked figure.
// 2. Chains
var promptTemplate =
@"Use the following pieces of context to answer the question at the end. If the answer is not in context then just say that you don't know, don't try to make up an answer. Keep the answer as short as possible. Always quote the context in your answer.
{context}
Question: {text}
Helpful Answer:";
var chain =
Set("Who was drinking a unicorn blood?") // set the question (default key is "text")
| RetrieveSimilarDocuments(vectorCollection, embeddingModel, amount: 5) // take 5 most similar documents
| CombineDocuments(outputKey: "context") // combine documents together and put them into context
| Template(promptTemplate) // replace context and question in the prompt with their values
| LLM(llm.UseConsoleForDebug()); // send the result to the language model
var chainAnswer = await chain.RunAsync("text"); // get chain result
Console.WriteLine("Chain Answer:"+ chainAnswer); // print the result
Console.WriteLine($"LLM usage: {llm.Usage}"); // Print usage and price
Console.WriteLine($"Embedding model usage: {embeddingModel.Usage}"); // Print usage and price
Priority place for bugs: https://github.com/tryAGI/LangChain/issues
Priority place for ideas and general questions: https://github.com/tryAGI/LangChain/discussions
Discord: https://discord.gg/Ca2xhfBf3v
It's licensed under . We do not plan to change the license in any foreseeable future for this project,
but projects based on this within the organization may have different licenses.
Some documentation is based on documentation from dotnet/docs repository
under CC BY 4.0 license,
where code examples are changed to code examples for using this project.
This project is supported by JetBrains through the Open Source Support Program.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.17.1 | 105 | 4/30/2026 |
| 0.17.1-dev.94 | 64 | 4/1/2026 |
| 0.17.1-dev.91 | 62 | 3/29/2026 |
| 0.17.1-dev.84 | 64 | 3/21/2026 |
| 0.17.1-dev.83 | 55 | 3/21/2026 |
| 0.17.1-dev.82 | 63 | 3/21/2026 |
| 0.17.1-dev.81 | 61 | 3/21/2026 |
| 0.17.1-dev.80 | 64 | 3/21/2026 |
| 0.17.1-dev.79 | 61 | 3/21/2026 |
| 0.17.1-dev.78 | 54 | 3/20/2026 |
| 0.17.1-dev.77 | 53 | 3/20/2026 |
| 0.17.1-dev.76 | 57 | 3/20/2026 |
| 0.17.1-dev.61 | 76 | 3/16/2026 |
| 0.17.1-dev.60 | 72 | 3/16/2026 |
| 0.17.1-dev.59 | 66 | 3/16/2026 |
| 0.17.1-dev.51 | 209 | 5/20/2025 |
| 0.17.1-dev.47 | 97 | 5/3/2025 |
| 0.17.1-dev.45 | 189 | 4/23/2025 |
| 0.17.1-dev.44 | 197 | 4/22/2025 |
| 0.17.1-dev.42 | 202 | 4/22/2025 |