Documentation Index
Fetch the complete documentation index at: https://nvd-54.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
概述
本概述涵盖基于文本的向量嵌入模型。LangChain 目前不支持多模态向量嵌入。
工作原理
- Vectorization — The model encodes each input string as a high-dimensional vector.
- Similarity scoring — Vectors are compared using mathematical metrics to measure how closely related the underlying texts are.
相似度指标
通常使用以下几种指标来比较向量嵌入:- Cosine similarity — measures the angle between two vectors.
- Euclidean distance — measures the straight-line distance between points.
- Dot product — measures how much one vector projects onto another.
接口
LangChain 通过 Embeddings 接口为文本向量嵌入模型(如 OpenAI、Cohere、Hugging Face)提供标准接口。 提供两个主要方法:embedDocuments(documents: string[]) → number[][]: Embeds a list of documents.embedQuery(text: string) → number[]: Embeds a single query.
该接口允许查询和文档使用不同的策略进行嵌入,尽管大多数提供商在实践中以相同方式处理它们。
安装和使用
OpenAI
OpenAI
安装依赖:添加环境变量:实例化模型:
Azure
Azure
安装依赖添加环境变量:实例化模型:
AWS
AWS
安装依赖:添加环境变量:实例化模型:
Google Gemini
Google Gemini
安装依赖:添加环境变量:实例化模型:
Google Vertex
Google Vertex
安装依赖:添加环境变量:实例化模型:
MistralAI
MistralAI
安装依赖:添加环境变量:实例化模型:
Cohere
Cohere
安装依赖:添加环境变量:实例化模型:
Ollama
Ollama
安装依赖:实例化模型:
缓存
向量嵌入可以被存储或临时缓存,以避免重新计算。 可以使用CacheBackedEmbeddings 来缓存向量嵌入。此包装器将向量嵌入存储在键值存储中,文本被哈希处理,哈希值用作缓存中的键。
The main supported way to initialize a CacheBackedEmbeddings is fromBytesStore. It takes the following parameters:
- underlyingEmbeddings: The embedder to use for embedding.
- documentEmbeddingStore: Any
BaseStorefor caching document embeddings. - options.namespace: (optional, defaults to
"") The namespace to use for the document cache. Helps avoid collisions (e.g., set it to the embedding model name).
所有集成
Alibaba Tongyi
Azure OpenAI
Baidu Qianfan
Amazon Bedrock
ByteDance Doubao
Cloudflare Workers AI
Cohere
DeepInfra
Fireworks
Google Generative AI
Google Vertex AI
Gradient AI
HuggingFace Inference
IBM watsonx.ai
Jina
Llama CPP
Minimax
MistralAI
Mixedbread AI
Nomic
Ollama
Oracle AI Database
OpenAI
Pinecone
Prem AI
Tencent Hunyuan
TensorFlow
TogetherAI
HuggingFace Transformers
Voyage AI
ZhipuAI
将这些文档连接到 Claude、VSCode 等工具,通过 MCP 获取实时答案。

