langchain-rust
Library Listed
LangChain for Rust, the easiest way to write LLM-based programs in Rust
- Downloads
- 4,306
- Dependents
- 4
- Stars
- 1,362
- Forks
- 179
- Contributors
- 39
- Commits
- 603
- Latest release
- 8.0.0 ·
About
⚡ Building applications with LLMs through composability, with Rust! ⚡
🤔 What is this?
This is the Rust language implementation of LangChain.
Read the full README
Current Features
LLMs
Embeddings
- [x] OpenAi
- [x] Azure OpenAi
- [x] Ollama
- [x] Local FastEmbed
- [x] Voyage AI
- [x] MistralAI
- [x] AWS Bedrock (Titan, Cohere)
VectorStores
Chain
- [x] LLM Chain
- [x] Conversational Chain
- [x] Conversational Retriever Simple
- [x] Conversational Retriever With Vector Store
- [x] Sequential Chain
- [x] Q&A Chain
- [x] Map-reduce / refine / map-rerank + Retrieval QA
- [x] SQL Chain
- [x] LLM Math Chain (word problems, exact arithmetic)
- [x] Router Chain (LLM picks the chain)
- [x] Constitutional Chain (critique and revise against principles)
- [x] Transform Chain (your own function as a chain step)
- [x] API Chain (answer from an HTTP API, allowed URLs only)
Output parsers
Memory
Agents
Tools
- [x] Custom tools from async functions (
FunctionTool) - [x] Calculator
- [x] Serpapi/Google
- [x] DuckDuckGo Search
- [x] Exa web search
- [x] Firecrawl web search and scrape
- [x] Wolfram/Math
- [x] Command line
- [x] Text2Speech
- [x] Wikipedia
- [x] Perplexity web search
- [x] Custom tools from async functions (
Semantic Routing
- [x] Static Routing
- [x] Dynamic Routing
Document Loaders
[x] PDF
use futures_util::StreamExt; async fn main() { let path = "./src/document_loaders/test_data/sample.pdf"; let loader = PdfExtractLoader::from_path(path).expect("Failed to create PdfExtractLoader"); // let loader = LoPdfLoader::from_path(path).expect("Failed to create LoPdfLoader"); let docs = loader .load() .await .unwrap() .map(|d| d.unwrap()) .collect::<Vec<_>>() .await; }[x] Pandoc
use futures_util::StreamExt; async fn main() { let path = "./src/document_loaders/test_data/sample.docx"; let loader = PandocLoader::from_path(InputFormat::Docx.to_string(), path) .await .expect("Failed to create PandocLoader"); let docs = loader .load() .await .unwrap() .map(|d| d.unwrap()) .collect::<Vec<_>>() .await; }[x] HTML
use futures_util::StreamExt; use url::Url; async fn main() { let path = "./src/document_loaders/test_data/example.html"; let html_loader = HtmlLoader::from_path(path, Url::parse("https://example.com/").unwrap()) .expect("Failed to create html loader"); let documents = html_loader .load() .await .unwrap() .map(|x| x.unwrap()) .collect::<Vec<_>>() .await; }[x] HTML To Markdown
use futures_util::StreamExt; use url::Url; async fn main() { let path = "./src/document_loaders/test_data/example.html"; let html_to_markdown_loader = HtmlToMarkdownLoader::from_path(path, Url::parse("https://example.com/").unwrap(), HtmlToMarkdownOptions::default().with_skip_tags(vec!["figure".to_string()])) .expect("Failed to create html to markdown loader"); let documents = html_to_markdown_loader .load() .await .unwrap() .map(|x| x.unwrap()) .collect::<Vec<_>>() .await; }[x] CSV
use futures_util::StreamExt; async fn main() { let path = "./src/document_loaders/test_data/test.csv"; let columns = vec![ "name".to_string(), "age".to_string(), "city".to_string(), "country".to_string(), ]; let csv_loader = CsvLoader::from_path(path, columns).expect("Failed to create csv loader"); let documents = csv_loader .load() .await .unwrap() .map(|x| x.unwrap()) .collect::<Vec<_>>() .await; }[x] Git commits
use futures_util::StreamExt; async fn main() { let path = "/path/to/git/repo"; let git_commit_loader = GitCommitLoader::from_path(path).expect("Failed to create git commit loader"); let documents = csv_loader .load() .await .unwrap() .map(|x| x.unwrap()) .collect::<Vec<_>>() .await; }[x] Source code
let loader_with_dir = SourceCodeLoader::from_path("./src/document_loaders/test_data".to_string()) .with_dir_loader_options(DirLoaderOptions { glob: None, suffixes: Some(vec!["rs".to_string()]), exclude: None, }); let stream = loader_with_dir.load().await.unwrap(); let documents = stream.map(|x| x.unwrap()).collect::<Vec<_>>().await;[x] Notion export (
NotionDirectoryLoader::new("./Export-..."), Markdown & CSV export)
Installation
This library heavily relies on serde_json for its operation.
Step 1: Add serde_json
First, ensure serde_json is added to your Rust project.
cargo add serde_json
Step 2: Add langchain-rust
Then, you can add langchain-rust to your Rust project.
Simple install
cargo add langchain-rust
With Sqlite
sqlite-vss
Download additional sqlite_vss libraries from https://github.com/asg017/sqlite-vss
cargo add langchain-rust --features sqlite-vss
sqlite-vec
Download additional sqlite_vec libraries from https://github.com/asg017/sqlite-vec
cargo add langchain-rust --features sqlite-vec
With Postgres
cargo add langchain-rust --features postgres
With SurrialDB
cargo add langchain-rust --features surrealdb
With Weaviate
cargo add langchain-rust --features weaviate
With Milvus
cargo add langchain-rust --features milvus
With Pinecone
cargo add langchain-rust --features pinecone
With Qdrant
cargo add langchain-rust --features qdrant
With Chroma
cargo add langchain-rust --features chroma
With MongoDB (Atlas vector store, chat history on any MongoDB)
cargo add langchain-rust --features mongodb
With Redis (chat history and vector store)
cargo add langchain-rust --features redis
Please remember to replace the feature flags sqlite, postgres or surrealdb based on your
specific use case.
This will add both serde_json and langchain-rust as dependencies in your Cargo.toml
file. Now, when you build your project, both dependencies will be fetched and compiled, and will be available for use in your project.
Remember, serde_json is a necessary dependencies, and sqlite, postgres and surrealdb
are optional features that may be added according to project needs.
Quick Start Conversational Chain
use langchain_rust::{
chain::{Chain, LLMChainBuilder},
fmt_message, fmt_placeholder, fmt_template,
language_models::llm::LLM,
llm::openai::{OpenAI, OpenAIModel},
message_formatter,
prompt::HumanMessagePromptTemplate,
prompt_args,
schemas::messages::Message,
template_fstring,
};
#[tokio::main]
async fn main() {
//We can then initialize the model:
// If you'd prefer not to set an environment variable you can pass the key in directly via the `openai_api_key` named parameter when initiating the OpenAI LLM class:
// let open_ai = OpenAI::default()
// .with_config(
// OpenAIConfig::default()
// .with_api_key("<your_key>"),
// ).with_model(OpenAIModel::Gpt4oMini.to_string());
let open_ai = OpenAI::default().with_model(OpenAIModel::Gpt4oMini.to_string());
//Once you've installed and initialized the LLM of your choice, we can try using it! Let's ask it what LangSmith is - this is something that wasn't present in the training data so it shouldn't have a very good response.
let resp = open_ai.invoke("What is rust").await.unwrap();
println!("{}", resp);
// We can also guide it's response with a prompt template. Prompt templates are used to convert raw user input to a better input to the LLM.
let prompt = message_formatter![
fmt_message!(Message::new_system_message(
"You are world class technical documentation writer."
)),
fmt_template!(HumanMessagePromptTemplate::new(template_fstring!(
"{input}", "input"
)))
];
//We can now combine these into a simple LLM chain:
let chain = LLMChainBuilder::new()
.prompt(prompt)
.llm(open_ai.clone())
.build()
.unwrap();
//We can now invoke it and ask the same question. It still won't know the answer, but it should respond in a more proper tone for a technical writer!
match chain
.invoke(prompt_args! {
"input" => "Quien es el escritor de 20000 millas de viaje submarino",
})
.await
{
Ok(result) => {
println!("Result: {:?}", result);
}
Err(e) => panic!("Error invoking LLMChain: {:?}", e),
}
//If you want to prompt to have a list of messages you could use the `fmt_placeholder` macro
let prompt = message_formatter![
fmt_message!(Message::new_system_message(
"You are world class technical documentation writer."
)),
fmt_placeholder!("history"),
fmt_template!(HumanMessagePromptTemplate::new(template_fstring!(
"{input}", "input"
))),
];
let chain = LLMChainBuilder::new()
.prompt(prompt)
.llm(open_ai)
.build()
.unwrap();
match chain
.invoke(prompt_args! {
"input" => "Who is the writer of 20,000 Leagues Under the Sea, and what is my name?",
"history" => vec![
Message::new_human_message("My name is: luis"),
Message::new_ai_message("Hi luis"),
],
})
.await
{
Ok(result) => {
println!("Result: {:?}", result);
}
Err(e) => panic!("Error invoking LLMChain: {:?}", e),
}
}
Compatibility
- Runs on
- GPU support unknown
What shows it
- no dependency or feature matches a backend row
- Native code
- Optional
- Binds native code: tree-sitter (feature tree-sitter), ort-sys (feature fastembed), ring (feature surrealdb), tree-sitter-language (feature tree-sitter)
- Build uses a native toolchain: cc (feature tree-sitter)
- Python bindings
- No Python binding crate found
- License
- MIT
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
LangChain for Rust, the easiest way to write LLM-based programs in Rust |
4,306 downloads over 30 days | 4 | 1,362 | 8.0.0 | GPU support unknown | Binds native code: tree-sitter (feature tree-sitter), ort-sys (feature fastembed), ring (feature surrealdb), tree-sitter-language (feature tree-sitter). Build uses a native toolchain: cc (feature tree-sitter) | MIT |
|
rust-mcp-sdk Featured
An asynchronous SDK and framework for building MCP-Servers and MCP-Clients, leveraging the rust-mcp-schema for type safe MCP Schema Objects. |
29,764 downloads over 30 days | 51 | 199 | 2.0.0 | GPU support unknown | No native code found | MIT |
|
yoagent Listed
The agent loop for Rust: stream from 7 LLM protocols, run tools, loop until done. Native or wasm32 (Cloudflare Workers). |
2,027 downloads over 30 days | 5 | 369 | 0.27.4 | GPU support unknown | No native code found | MIT |
|
The autonomous, self-improving AI agent. Single Rust binary. Every channel. Recommended: the 40MB prebuilt binary for macOS, Linux and Windows: https://github.com/opencrabs/opencrabs/releases |
125 binary downloads per release | Not applicable | 1,027 | 0.5.15 | GPU support unknown | Binds native code: libsqlite3-sys, llama-cpp-sys-2, opusic-sys (feature local-tts), tree-sitter (feature code-graph), alsa-sys (feature local-stt) and 1 more | MIT |
|
yomo Listed
A QUIC-based runtime for AI-LLM tool routing and serverless execution |
26 downloads over 30 days | 0 | 1,930 | 2.1.6 | GPU support unknown | No native code found | Apache-2.0 |
|
edgequake Listed
Rust SDK for the EdgeQuake RAG platform |
11 downloads over 30 days | 0 | 2,297 | 0.4.1 | GPU support unknown | No native code found | Apache-2.0 |
|
An open protocol that gives AI agents a secure, sandboxed place to run code and use tools — with lean context usage. AXP works alongside MCP |
Not measured | Not applicable | 3 | Not measured | Not measured | Not measured | Apache-2.0 |
Why ListedNo archive, New or Featured rule places it, so it is Listed.
What it lacks for Featured
- It has 0 active dependents and 0 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days. The repository route reads 1,362 stars, 179 forks and 39 contributors. It needs 4,539 stars, 434 forks and 79 contributors together.
What else the check found
- The last activity is on 3 Nov 2026, 6 days ago. The rules expect an update within 365 days. Dormancy rule
Exact rules: Listed, Featured library. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: version 8.0.0 base 200, raised to the 365-day floor: E = 365 daysdormancy: last activity 2026-11-03, 6 days ago, E = 365: activefeatured: not featured: active_users 0 < 11 and new_adopters 0 < 9 and repository route stars 1362 (needs 4539), forks 179 (needs 434), contributors 39 (needs 79)listed: listed: no archive, new or featured rule applies
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources6 sources
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption0 active dependents, 0 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 0 | crates.io database dump | Yes | |
| New dependents (365 days) | 0 | crates.io database dump | Yes | |
| Peak active dependents | 4 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 0.925 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 6 days ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2026-11-03 | GitHub repository | Yes | |
| Latest release | 2026-11-03 | crates.io database dump | Yes | |
| First release | 2024-04-16 | crates.io database dump | Yes | |
| Latest version | 8.0.0 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 0 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 52 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | none | crates.io database dump | Yes |
Distribution23 releases, 4,306 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 23 | crates.io database dump | Yes | |
| Downloads over 30 days | 4306 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | false | crates.io database dump | Yes | |
| Every version 0.0.x | false | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository1,362 stars, 179 forks, 39 contributors, 603 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 1362 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 179 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 39 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 603 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | MIT | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | GPU support unknown | crates.io database dump | No | |
| What shows each backend | no dependency or feature matches a backend row | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | Binds native code: tree-sitter (feature tree-sitter), ort-sys (feature fastembed), ring (feature surrealdb), tree-sitter-language (feature tree-sitter). Build uses a native toolchain: cc (feature tree-sitter) | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 4 | crates.io database dump | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.