Skip to main content
Databricks Lakehouse Platform unifies data, analytics, and AI on one platform.
This guide provides a quick overview for getting started with DatabricksEmbeddings embedding models. For detailed documentation of all DatabricksEmbeddings features and configurations head to the API reference.

Overview

Integration details

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 state-of-the-art 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 embedding models 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.

Setup

To access Databricks models you’ll need to create a 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.

Installation

The LangChain Databricks integration lives in the databricks-langchain package:

Instantiation

Indexing and retrieval

Embedding models are often used in retrieval-augmented generation (RAG) flows, both as part of indexing data as well as later retrieving it. For more detailed instructions, please see our RAG tutorials. Below, see how to index and retrieve data using the embeddings object we initialized above. In this example, we will index and retrieve a sample document in the InMemoryVectorStore.

Direct usage

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 reference

For detailed documentation on DatabricksEmbeddings features and configuration options, please refer to the API reference.