Skip to main content
Databricks Lakehouse Platform unifies data, analytics, and AI on one platform.
本指南提供了开始使用 DatabricksEmbeddings 向量嵌入模型. 有关所有 DatabricksEmbeddings 功能和配置的详细文档,请前往 API reference.

概述

集成详情

Supported methods

DatabricksEmbeddings supports all methods of Embeddings class including async APIs.

Endpoint requirement

The serving endpoint DatabricksEmbeddings wraps must have OpenAI-compatible embedding input/output format (reference). As long as the input format is compatible, DatabricksEmbeddings can be used for any endpoint type hosted on Databricks Model Serving:
  1. Foundation Models - Curated list of 先进的 foundation models such as BAAI General Embedding (BGE). These endpoint are ready to use in your Databricks workspace without any set up.
  2. Custom Models - You can also deploy custom 向量嵌入模型 to a serving endpoint via MLflow with your choice of framework such as LangChain, Pytorch, Transformers, etc.
  3. External Models - Databricks endpoints can serve models that are hosted outside Databricks as a proxy, such as proprietary model service like OpenAI text-embedding-3.

设置

要访问 Databricks 模型,您需要创建一个 Databricks account, set up credentials (only if you are outside Databricks workspace), and install required packages.

Credentials (only if you are outside databricks)

If you are running LangChain app inside Databricks, you can skip this step. Otherwise, you need manually set the Databricks workspace hostname and personal access token to DATABRICKS_HOST and DATABRICKS_TOKEN environment variables, respectively. See Authentication Documentation for how to get an access token.

安装

LangChain 的 Databricks 集成位于 databricks-langchain 包中:

实例化

索引与检索

向量嵌入模型常用于检索增强生成 (RAG) 流程中, 既用于索引数据,也用于后续检索数据。 更详细的说明请参阅我们的 RAG tutorials. 下面展示如何使用 embeddings 对象来索引和检索数据。 在此示例中,我们将在 InMemoryVectorStore.

直接使用

Under the hood, the vectorstore and retriever implementations are calling embeddings.embed_documents(...) and embeddings.embed_query(...) to create embeddings for the text(s) used in from_texts and retrieval invoke operations, respectively. You can directly call these methods to get embeddings for your own use cases.

Embed single texts

You can embed single texts or documents with embed_query:

Embed multiple texts

You can embed multiple texts with embed_documents:

Async usage

You can also use aembed_query and aembed_documents for producing embeddings asynchronously:

API 参考

For detailed documentation on DatabricksEmbeddings 功能和配置选项的详细文档,请参阅 API reference.