Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

langchain-rust

> AI 编程
Open source

️LangChain for Rust, the easiest way to write LLM-based programs in Rust

1.3K stars0 likes1 views
WebsiteGitHub

About

️LangChain for Rust, the easiest way to write LLM-based programs in Rust

️LangChain Rust

Latest Version

⚡ Building applications with LLMs through composability, with Rust! ⚡

What is this?

This is the Rust language implementation of LangChain.

Current Features

  • LLMs

    • OpenAi
    • Azure OpenAi
    • Ollama
    • Anthropic Claude
  • Embeddings

    • OpenAi
    • Azure OpenAi
    • Ollama
    • Local FastEmbed
    • MistralAI
  • VectorStores

    • OpenSearch
    • Postgres
    • Qdrant
    • Sqlite
    • SurrealDB
  • Chain

    • LLM Chain
    • Conversational Chain
    • Conversational Retriever Simple
    • Conversational Retriever With Vector Store
    • Sequential Chain
    • Q&A Chain
    • SQL Chain
  • Agents

    • Chat Agent with Tools
    • Open AI Compatible Tools Agent
  • Tools

    • Serpapi/Google
    • DuckDuckGo Search
    • Wolfram/Math
    • Command line
    • Text2Speech
  • Semantic Routing

    • Static Routing
    • Dynamic Routing
  • Document Loaders

    • PDF

      rust
      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::>()
              .await;
      
      }
    • Pandoc

      rust
      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::>()
              .await;
      }
    • HTML

      rust
      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::>()
              .await;
      }
    • HTML To Markdown

…
  • CSV

    rust
    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::>()
            .await;
    }
  • Git commits

    rust
    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::>()
            .await;
    }
  • Source code

    rust
    
    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::>().await;

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.

bash
cargo add serde_json

Step 2: Add langchain-rust

Then, you can add langchain-rust to your Rust project.

Simple install

bash
cargo add langchain-rust

With Sqlite

sqlite-vss

Download additional sqlite_vss libraries from

bash
cargo add langchain-rust --features sqlite-vss
sqlite-vec

Download additional sqlite_vec libraries from

bash
cargo add langchain-rust --features sqlite-vec

With Postgres

bash
cargo add langchain-rust --features postgres

With SurrialDB

bash
cargo add langchain-rust --features surrealdb

With Qdrant

bash
cargo add langchain-rust --features qdrant

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

…

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustlangchainllmllmsopenai

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryAI 编程
PricingOpen source

> Related tools

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.