设置
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 toDATABRICKS_HOST and DATABRICKS_TOKEN environment variables, respectively. See Authentication Documentation for how to get an access token.
安装
The LangChain Databricks integration lives in thedatabricks-langchain package.
Create a vector search endpoint and index (if you haven’t already)
In this section, we will create a Databricks Vector Search endpoint and an index using the client SDK. If you already have an endpoint and an index, you can skip the section and go straight to “Instantiation” section. First, instantiate the Databricks VectorSearch client:DatabricksVectorSearch class support both use cases.
- Delta Sync Index automatically syncs with a source Delta Table, automatically and incrementally updating the index as the underlying data in the Delta Table changes.
- Direct Vector Access Index supports direct read and write of vectors and metadata. The user is responsible for updating this table using the REST API or the Python SDK.
实例化
The instantiation ofDatabricksVectorSearch is a bit different depending on whether your index uses Databricks-managed embeddings or self-managed embeddings i.e. LangChain Embeddings object of your choice.
If you are using a delta-sync index with Databricks-managed embeddings:
管理向量存储
向向量存储添加项目
Note: Adding items to vector store viaadd_documents method is only supported for a direct-access index.
从向量存储删除项目
Note: Deleting items to vector store viadelete method is only supported for a direct-access index.
查询向量存储
一旦创建了向量存储并添加了相关文档,您很可能希望在链或智能体运行期间对其进行查询。直接查询
可以按以下方式执行简单的相似度搜索:columns parameter when initializing the vector store.
转换为检索器进行查询
您还可以将向量存储转换为检索器,以便在链中更方便地使用。用于检索增强生成
有关如何将此向量存储用于检索增强生成 (RAG) 的指南,请参阅以下部分:API 参考
For detailed documentation of allDatabricksVectorSearch features and configurations head to the API reference: api-docs.databricks.com/python/databricks-ai-bridge/latest/databricks_langchain.html#databricks_langchain.DatabricksVectorSearch
连接这些文档到 Claude、VSCode 等工具,通过 MCP 获取实时答案。

