Indexing multimodal content: vectorization of images and text in Azure AI Search
A guide to setting up multimodal search in Azure AI Search using vectorization of text and images. Describes steps for creating an index, selecting models (e.g., CLIP), methods for generating embeddings, and executing hybrid queries to improve relevance.
On this page
The short answer
For direct text-to-image search, use the paired text and image encoders of one compatible multimodal model. Equal vector length is necessary for a field but does not align independently trained embedding spaces. Store the image vectors in a vector field and searchable captions in a text field; generate query vectors with the matching text encoder. Hybrid ranking combines result lists but still needs evaluation on representative queries.
Understanding multimodal search in Azure AI Search
Multimodal search in Azure AI Search enables finding similar content regardless of type - text or image - by converting data into numerical vectors (embeddings) where vector proximity reflects semantic similarity. For example, the query "puppy" can return dog images even without textual labels.
This approach relies on vector search, supporting not only text-to-text but also text-to-image matching, which is valuable in hybrid scenarios. Vectorization captures conceptual similarity, such as between "dog" and "canine", or between text and its corresponding image.
Preparing the index for vector data
The vector field type is Collection(Edm.Single), not scalar Edm.Single. Its dimensions must match the chosen encoder. The example assumes a 512-component encoder, not a universal CLIP or Azure dimension. Install azure-search-documents with python -m pip install azure-search-documents and use an SDK exposing HnswAlgorithmConfiguration and VectorSearchProfile. The configuration below links a named algorithm to a named profile and enables full-text search on text. It constructs an index definition locally and would print ['id', 'text', 'image_vector']; it neither creates an Azure resource nor uploads documents. Publication requires a configured service and authenticated index-management client.
from azure.search.documents.indexes.models import (
SearchIndex, SearchField, SearchFieldDataType, VectorSearch,
HnswAlgorithmConfiguration, VectorSearchProfile,
)
dimensions = 512 # Example only: use the chosen encoder's actual output length.
profile = "multimodal-profile"
index = SearchIndex(
name="multimodal-index",
fields=[
SearchField(name="id", type=SearchFieldDataType.String, key=True),
SearchField(name="text", type=SearchFieldDataType.String, searchable=True),
SearchField(
name="image_vector",
type=SearchFieldDataType.Collection(SearchFieldDataType.Single),
searchable=True,
vector_search_dimensions=dimensions,
vector_search_profile_name=profile,
),
],
vector_search=VectorSearch(
algorithms=[HnswAlgorithmConfiguration(name="hnsw-config")],
profiles=[VectorSearchProfile(name=profile, algorithm_configuration_name="hnsw-config")],
),
)
print([field.name for field in index.fields])Choosing a model for image vectorization
Choose a jointly trained image/text encoder pair and preserve its model version and preprocessing. CLIP is one family of such models; different checkpoints can use different vector lengths. A query encoded by an unrelated text-only embedding model cannot meaningfully search the image space merely because its vector has the same length. Changing the model normally requires regenerating indexed vectors.
Choosing a model for text vectorization
Two valid designs should be distinguished. Direct image search uses the paired text encoder to compare a text query with image embeddings. Alternatively, generate image captions and embed both captions and queries with one text model; then retrieval operates on descriptions and can miss visual details absent from them. Do not compare a text-only ada-002 or SBERT vector directly with a CLIP image vector.
Integrated vs external vectorization
During ingestion, indexer skillsets can extract content and generate embeddings. A query-time vectorizer is a separate configuration for converting query input into vectors; an embedding skill alone does not configure query vectorization. External vectorization instead computes document vectors before upload and query vectors in the application. Either route must preserve the same model, preprocessing and dimensions for each space.
Creating a multimodal index
A multimodal index combines text, images, and their vector representations in one schema. Fields like text and image_vector allow both full-text and vector search, forming the basis for hybrid queries.
Executing a multimodal search query
The helper below constructs a request body; it is not a complete network client and does not generate an embedding. Pass a real vector from the paired text encoder, then send the body using the service endpoint, supported REST API version and credentials. The length check catches a schema mismatch but cannot prove model compatibility. Full-text search uses searchable text; the vector branch searches image_vector. RRF merges ranks without guaranteeing that the merged answer is more relevant.
def hybrid_payload(query_vector):
# Precondition: query_vector comes from the paired text encoder
# compatible with the indexed image encoder; length alone is insufficient.
if len(query_vector) != 512:
raise ValueError("Expected the example encoder's 512 components")
return {
"search": "puppy",
"vectorQueries": [{
"kind": "vector", "vector": list(query_vector),
"k": 10, "fields": "image_vector",
}],
"select": "id,text", "top": 5,
}Evaluating and improving search results
Evaluate a labeled set of query/result pairs and compare vector-only, text-only and hybrid retrieval. Semantic ranking requires supported content and its own configuration. Tune k and filters against this set. Oversampling is associated with supported compressed-vector rescoring configurations, so it is not a universal switch for an uncompressed index. The illustrative precision calculation below measures the selected binary decisions, not every retrieval quality dimension.
from sklearn.metrics import precision_score
# Example evaluation (hypothetical values)
y_true = [1, 0, 1, 1, 0] # 1 = relevant, 0 = not
y_pred = [1, 1, 1, 0, 0] # predicted results
precision = precision_score(y_true, y_pred, average='binary')
print(f"Precision: {precision:.2f}")Things to check
- Paired image and text encoders use one compatible space and version
- Vector dimensions match the field; equal length alone does not prove compatibility
- The vector field points to an existing profile and algorithm; captions are searchable
- Query vectorization is configured separately from ingestion skills
- Quality is compared on labeled queries; ranking improvements are not assumed
Where this applies
Check service capabilities rather than assuming every service created before a specific date is unsupported. Some older services cannot add vector indexes and require migration. Embedding generation, image description, indexing and optional semantic ranking can have separate costs. The snippets illustrate schema construction and request shape; they do not establish retrieval quality.