Add a vector search index resource to a Databricks app
Add vector search indexes as Databricks Apps resources to enable semantic search and similarity-based retrieval in your applications. Vector search indexes store and query high-dimensional vector embeddings, powering use cases like retrieval-augmented generation (RAG), semantic search, and recommendation systems.
Privilege requirements
To access a vector search index, the app's service principal must have the USE CATALOG privilege on the parent catalog, the USE SCHEMA privilege on the parent schema, and the SELECT privilege on the index. When you add the index resource, Databricks automatically grants these privileges to the app's service principal.
For this automatic granting to succeed, one of the following must be true for each privilege:
- For
USE CATALOG: Either all account users have theUSE CATALOGprivilege on the catalog, or you have theMANAGEprivilege on the catalog. - For
USE SCHEMA: Either all account users have theUSE SCHEMAprivilege on the schema, or you have theMANAGEprivilege on the schema. - For
SELECT: Either all account users have theSELECTprivilege on the index, or you have theMANAGEprivilege on the index.
For more information about querying vector search indexes with these permissions, see How to query a vector search index.
See Unity Catalog privileges and securable objects.
Add a vector search index resource
Before you add a vector search index as a resource, review the app resource prerequisites.
- When you create or edit an app, navigate to the Configure step.
- In the App resources section, click + Add resource.
- Select Vector search index as the resource type.
- Choose a vector search index from the available indexes in your workspace. The index must already exist in Unity Catalog.
- Select the permission level for your app:
- Can select: Grants the app permission to query the vector search index for similarity searches. Corresponds to the SELECT privilege.
- (Optional) Specify a custom resource key, which is how you reference the index in your app configuration. The default key is
vector-search-index.
Vector search indexes are Unity Catalog tables with type TABLE_ONLINE_VECTOR_INDEX_REPLICA or TABLE_ONLINE_VECTOR_INDEX_DIRECT. When you select a vector search index, you're selecting a specially configured table that supports semantic search operations.
Environment variables
When you deploy an app with a vector search index resource, Databricks exposes the full three-level name through environment variables that you can reference using the valueFrom field.
Example configuration:
env:
- name: VECTOR_SEARCH_INDEX
valueFrom: vector-search-index # Use your custom resource key if different
Using the index in your application:
import os
from databricks.sdk import WorkspaceClient
# Access the vector search index name
index_name = os.getenv("VECTOR_SEARCH_INDEX")
# Initialize workspace client
w = WorkspaceClient()
# Query the vector search index
results = w.vector_search_indexes.query_index(
index_name=index_name,
query_text="What is machine learning?",
num_results=10
)
# Process results
for result in results.manifest.columns:
print(f"Result: {result}")
For more information, see Use environment variables to access resources.
Remove a vector search index resource
When you remove a vector search index resource from an app, the app's service principal loses access to the index. The index itself remains unchanged and continues to be available for other users and applications that have appropriate permissions.
Best practices
Consider the following when you work with vector search index resources:
- Make sure the app's service principal has access to underlying data sources if the index references other tables.
- Monitor query performance and adjust index configuration or embedding models if response times degrade.
- Consider index refresh schedules to keep embeddings synchronized with source data.
- Use appropriate similarity metrics (cosine, euclidean, dot product) based on your embedding model.