返回顶部
🇺🇸 English
🇨🇳 简体中文
🇨🇳 繁體中文
🇺🇸 English
🇯🇵 日本語
🇰🇷 한국어
🇫🇷 Français
🇩🇪 Deutsch
🇪🇸 Español
🇷🇺 Русский
L

LangChain

Avoid common LangChain mistakes — LCEL gotchas, memory persistence, RAG chunking, and output parser traps.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
1,345
下载量
2
收藏
概述
安装方式
版本历史

LangChain

## LCEL Basics - `|` pipes output to next — `prompt | llm | parser` - `RunnablePassthrough()` forwards input unchanged — use in parallel branches - `RunnableParallel` runs branches concurrently — `{"a": chain1, "b": chain2}` - `.invoke()` for single, `.batch()` for multiple, `.stream()` for tokens - Input must match expected keys — `{"question": x}` not just `x` if prompt expects `{question}` ## Memory Gotchas - Memory doesn't auto-persist between sessions — save/load explicitly - `ConversationBufferMemory` grows unbounded — use `ConversationSummaryMemory` for long chats - Memory key must match prompt variable — `memory_key="chat_history"` needs `{chat_history}` in prompt - `return_messages=True` for chat models — `False` returns string for completion models ## RAG Chunking - Chunk size affects retrieval quality — too small loses context, too large dilutes relevance - Chunk overlap prevents cutting mid-sentence — 10-20% overlap typical - `RecursiveCharacterTextSplitter` preserves structure — splits on paragraphs, then sentences - Embedding dimension must match vector store — mixing models causes silent failures ## Output Parsers - `PydanticOutputParser` needs format instructions in prompt — call `.get_format_instructions()` - Parser failures aren't always loud — malformed JSON may partially parse - `OutputFixingParser` retries with LLM — wraps another parser, fixes errors - `with_structured_output()` on chat models — cleaner than manual parsing for supported models ## Retrieval - `similarity_search` returns documents — `.page_content` for text - `k` parameter controls results count — more isn't always better, noise increases - Metadata filtering before similarity — `filter={"source": "docs"}` in most vector stores - `max_marginal_relevance_search` for diversity — avoids redundant similar chunks ## Agents - Agents decide tool order dynamically — chains are fixed sequence - Tool descriptions matter — agent uses them to decide when to call - `handle_parsing_errors=True` — prevents crash on malformed agent output - Max iterations prevents infinite loops — `max_iterations=10` default may be too low ## Common Mistakes - Prompt template variables case-sensitive — `{Question}` ≠ `{question}` - Chat models need message format — `ChatPromptTemplate`, not `PromptTemplate` - Callbacks not propagating — pass `config={"callbacks": [...]}` through chain - Rate limits crash silently sometimes — wrap in retry logic - Token count exceeds context — use `trim_messages` or summarization for long histories

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 langchain-1776328706 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 langchain-1776328706 技能

通过命令行安装

skillhub install langchain-1776328706

下载 Zip 包

⬇ 下载 LangChain v1.0.0

文件大小: 2 KB | 发布时间: 2026-4-17 14:26

v1.0.0 最新 2026-4-17 14:26
Initial release

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部