0
# Data Models and Types
1
2
This document covers the comprehensive type system for Azure Search Documents, including search request/response models, index schema definitions, AI enrichment configurations, and all enumeration types. These types provide complete type safety and IntelliSense support for all Azure Search operations.
3
4
## Capabilities
5
6
### Search Query Models
7
8
Types for constructing and executing search queries with various modes and options.
9
10
```python { .api }
11
# Query types enumeration
12
class QueryType(str, Enum):
13
"""Types of search queries."""
14
SIMPLE = "simple" # Simple Lucene query syntax
15
FULL = "full" # Full Lucene query syntax
16
SEMANTIC = "semantic" # Semantic search with AI ranking
17
18
# Search modes
19
class SearchMode(str, Enum):
20
"""Search behavior for multiple terms."""
21
ANY = "any" # Match any search terms (OR)
22
ALL = "all" # Match all search terms (AND)
23
24
# Autocomplete modes
25
class AutocompleteMode(str, Enum):
26
"""Autocomplete suggestion behavior."""
27
ONE_TERM = "oneTerm" # Complete one term
28
TWO_TERMS = "twoTerms" # Complete up to two terms
29
ONE_TERM_WITH_CONTEXT = "oneTermWithContext" # One term with context
30
31
# Scoring statistics
32
class ScoringStatistics(str, Enum):
33
"""Statistics used for scoring."""
34
LOCAL = "local" # Use local statistics
35
GLOBAL = "global" # Use global statistics
36
```
37
38
### Vector Search Models
39
40
Types for vector similarity search and hybrid query scenarios.
41
42
```python { .api }
43
# Base vector query class
44
class VectorQuery:
45
"""Base class for vector queries."""
46
k_nearest_neighbors: Optional[int] = None
47
fields: str
48
exhaustive: Optional[bool] = None
49
oversampling: Optional[float] = None
50
51
# Pre-computed vector query
52
class VectorizedQuery(VectorQuery):
53
"""Query with pre-computed vector embeddings."""
54
vector: List[float]
55
56
def __init__(
57
self,
58
*,
59
vector: List[float],
60
k_nearest_neighbors: Optional[int] = None,
61
fields: str,
62
exhaustive: Optional[bool] = None,
63
oversampling: Optional[float] = None
64
): ...
65
66
# Text-based vector query
67
class VectorizableTextQuery(VectorQuery):
68
"""Text query that will be vectorized by the service."""
69
text: str
70
71
def __init__(
72
self,
73
*,
74
text: str,
75
k_nearest_neighbors: Optional[int] = None,
76
fields: str,
77
exhaustive: Optional[bool] = None,
78
oversampling: Optional[float] = None
79
): ...
80
81
# Vector filter modes
82
class VectorFilterMode(str, Enum):
83
"""How to apply filters in vector search."""
84
PRE_FILTER = "preFilter" # Filter before vector search
85
POST_FILTER = "postFilter" # Filter after vector search
86
```
87
88
### Semantic Search Models
89
90
Types for AI-powered semantic search with natural language understanding.
91
92
```python { .api }
93
# Semantic search result types
94
class SemanticSearchResultsType(str, Enum):
95
"""Types of semantic search results."""
96
BASE_RESULTS = "baseResults" # Standard results
97
RERANKED_RESULTS = "rerankedResults" # AI-reranked results
98
99
# Query answer types
100
class QueryAnswerType(str, Enum):
101
"""Types of extractive answers."""
102
NONE = "none" # No answers
103
EXTRACTIVE = "extractive" # Extract answers from content
104
105
# Query caption types
106
class QueryCaptionType(str, Enum):
107
"""Types of semantic captions."""
108
NONE = "none" # No captions
109
EXTRACTIVE = "extractive" # Extract relevant passages
110
111
# Semantic error handling
112
class SemanticErrorMode(str, Enum):
113
"""Error handling for semantic search."""
114
PARTIAL = "partial" # Return partial results
115
FAIL = "fail" # Fail on semantic errors
116
117
class SemanticErrorReason(str, Enum):
118
"""Reasons for semantic search errors."""
119
CAPACITY_OVERLOADED = "capacityOverloaded"
120
TRANSIENT = "transient"
121
122
# Semantic search results
123
class QueryAnswerResult:
124
"""Extractive answer from semantic search."""
125
text: Optional[str] = None
126
highlights: Optional[str] = None
127
score: Optional[float] = None
128
129
class QueryCaptionResult:
130
"""Semantic caption highlighting relevant content."""
131
text: Optional[str] = None
132
highlights: Optional[str] = None
133
```
134
135
### Document Operation Models
136
137
Types for document indexing, updates, and batch operations.
138
139
```python { .api }
140
# Document operation types
141
class IndexAction(str, Enum):
142
"""Types of document operations."""
143
UPLOAD = "upload" # Add or replace document
144
MERGE = "merge" # Update existing document fields
145
MERGE_OR_UPLOAD = "mergeOrUpload" # Merge if exists, upload if not
146
DELETE = "delete" # Delete document
147
148
# Indexing operation result
149
class IndexingResult:
150
"""Result of a document indexing operation."""
151
key: str # Document key
152
status: bool # Success/failure status
153
error_message: Optional[str] = None # Error message if failed
154
status_code: int # HTTP status code
155
156
def succeeded(self) -> bool:
157
"""Check if the operation succeeded."""
158
return self.status and self.status_code < 400
159
```
160
161
### Index Schema Models
162
163
Complete type system for defining search index schemas and field configurations.
164
165
```python { .api }
166
# Field data types
167
class SearchFieldDataType(str, Enum):
168
"""Data types for search index fields."""
169
STRING = "Edm.String"
170
INT32 = "Edm.Int32"
171
INT64 = "Edm.Int64"
172
DOUBLE = "Edm.Double"
173
BOOLEAN = "Edm.Boolean"
174
DATE_TIME_OFFSET = "Edm.DateTimeOffset"
175
GEOGRAPHY_POINT = "Edm.GeographyPoint"
176
COMPLEX_TYPE = "Edm.ComplexType"
177
178
@staticmethod
179
def Collection(item_type: "SearchFieldDataType") -> str:
180
"""Create a collection type."""
181
return f"Collection({item_type.value})"
182
183
# Search field definition
184
class SearchField:
185
"""Definition of a field in a search index."""
186
name: str
187
type: SearchFieldDataType
188
key: bool = False
189
retrievable: bool = True
190
searchable: bool = False
191
filterable: bool = False
192
sortable: bool = False
193
facetable: bool = False
194
analyzer_name: Optional[str] = None
195
search_analyzer_name: Optional[str] = None
196
index_analyzer_name: Optional[str] = None
197
synonym_map_names: Optional[List[str]] = None
198
fields: Optional[List["SearchField"]] = None # For complex types
199
vector_search_dimensions: Optional[int] = None
200
vector_search_profile_name: Optional[str] = None
201
202
def __init__(
203
self,
204
*,
205
name: str,
206
type: SearchFieldDataType,
207
**kwargs
208
): ...
209
210
# Helper functions for common field types
211
def SearchableField(
212
name: str,
213
*,
214
collection: bool = False,
215
key: bool = False,
216
retrievable: bool = True,
217
sortable: bool = False,
218
filterable: bool = False,
219
facetable: bool = False,
220
analyzer_name: Optional[str] = None,
221
search_analyzer_name: Optional[str] = None,
222
index_analyzer_name: Optional[str] = None,
223
synonym_map_names: Optional[List[str]] = None
224
) -> SearchField:
225
"""Create a searchable field."""
226
227
def SimpleField(
228
name: str,
229
type: SearchFieldDataType,
230
*,
231
key: bool = False,
232
filterable: bool = False,
233
sortable: bool = False,
234
facetable: bool = False,
235
retrievable: bool = True
236
) -> SearchField:
237
"""Create a simple field."""
238
239
def ComplexField(
240
name: str,
241
*,
242
fields: List[SearchField],
243
collection: bool = False,
244
retrievable: bool = True
245
) -> SearchField:
246
"""Create a complex field with nested fields."""
247
248
# Complete index definition
249
class SearchIndex:
250
"""Complete search index definition."""
251
name: str
252
fields: List[SearchField]
253
scoring_profiles: Optional[List[ScoringProfile]] = None
254
default_scoring_profile: Optional[str] = None
255
cors_options: Optional[CorsOptions] = None
256
suggesters: Optional[List[Suggester]] = None
257
analyzers: Optional[List[LexicalAnalyzer]] = None
258
tokenizers: Optional[List[LexicalTokenizer]] = None
259
token_filters: Optional[List[TokenFilter]] = None
260
char_filters: Optional[List[CharFilter]] = None
261
encryption_key: Optional[SearchResourceEncryptionKey] = None
262
similarity: Optional[SimilarityAlgorithm] = None
263
semantic_search: Optional[SemanticSearch] = None
264
vector_search: Optional[VectorSearch] = None
265
e_tag: Optional[str] = None
266
```
267
268
### Vector Search Configuration Models
269
270
Types for configuring vector similarity search and hybrid retrieval.
271
272
```python { .api }
273
# Vector search configuration
274
class VectorSearch:
275
"""Vector search configuration for an index."""
276
algorithms: Optional[List[VectorSearchAlgorithmConfiguration]] = None
277
profiles: Optional[List[VectorSearchProfile]] = None
278
vectorizers: Optional[List[VectorSearchVectorizer]] = None
279
compressions: Optional[List[VectorSearchCompression]] = None
280
281
# Vector search profile
282
class VectorSearchProfile:
283
"""Named vector search configuration profile."""
284
name: str
285
algorithm_configuration_name: str
286
vectorizer_name: Optional[str] = None
287
compression_name: Optional[str] = None
288
289
# Algorithm configuration
290
class VectorSearchAlgorithmConfiguration:
291
"""Vector search algorithm configuration."""
292
name: str
293
kind: VectorSearchAlgorithmKind
294
295
def __init__(
296
self,
297
*,
298
name: str,
299
kind: VectorSearchAlgorithmKind,
300
**kwargs
301
): ...
302
303
class VectorSearchAlgorithmKind(str, Enum):
304
"""Types of vector search algorithms."""
305
HNSW = "hnsw" # Hierarchical Navigable Small World
306
EXHAUSTIVE_KNN = "exhaustiveKnn" # Exhaustive k-nearest neighbors
307
308
class VectorSearchAlgorithmMetric(str, Enum):
309
"""Distance metrics for vector similarity."""
310
COSINE = "cosine" # Cosine similarity
311
EUCLIDEAN = "euclidean" # Euclidean distance
312
DOT_PRODUCT = "dotProduct" # Dot product
313
314
# Vector compression
315
class VectorSearchCompression:
316
"""Vector compression configuration."""
317
name: str
318
kind: str
319
320
class BinaryQuantizationCompression(VectorSearchCompression):
321
"""Binary quantization compression."""
322
kind: str = "binaryQuantization"
323
rescore: Optional[bool] = None
324
325
class VectorSearchCompressionTarget(str, Enum):
326
"""Compression targets."""
327
SIZE = "size" # Optimize for storage size
328
SPEED = "speed" # Optimize for query speed
329
330
# Vectorizers
331
class VectorSearchVectorizer:
332
"""Base vectorizer configuration."""
333
name: str
334
kind: VectorSearchVectorizerKind
335
336
class VectorSearchVectorizerKind(str, Enum):
337
"""Types of vectorizers."""
338
AZURE_OPEN_AI = "azureOpenAI"
339
WEB_API = "webApi"
340
341
class AzureOpenAIVectorizer(VectorSearchVectorizer):
342
"""Azure OpenAI embedding vectorizer."""
343
kind: VectorSearchVectorizerKind = VectorSearchVectorizerKind.AZURE_OPEN_AI
344
azure_open_ai_parameters: Optional[AzureOpenAIVectorizerParameters] = None
345
346
class AzureOpenAIVectorizerParameters:
347
"""Parameters for Azure OpenAI vectorizer."""
348
resource_uri: Optional[str] = None
349
deployment_id: Optional[str] = None
350
api_key: Optional[str] = None
351
model_name: Optional[AzureOpenAIModelName] = None
352
353
class AzureOpenAIModelName(str, Enum):
354
"""Azure OpenAI embedding models."""
355
TEXT_EMBEDDING_ADA_002 = "text-embedding-ada-002"
356
TEXT_EMBEDDING_3_LARGE = "text-embedding-3-large"
357
TEXT_EMBEDDING_3_SMALL = "text-embedding-3-small"
358
359
class WebApiVectorizer(VectorSearchVectorizer):
360
"""Custom web API vectorizer."""
361
kind: VectorSearchVectorizerKind = VectorSearchVectorizerKind.WEB_API
362
web_api_parameters: Optional[WebApiVectorizerParameters] = None
363
364
class WebApiVectorizerParameters:
365
"""Parameters for web API vectorizer."""
366
uri: Optional[str] = None
367
http_method: Optional[str] = None
368
http_headers: Optional[Dict[str, str]] = None
369
auth_resource_id: Optional[str] = None
370
```
371
372
### AI Enrichment Skill Models
373
374
Types for configuring cognitive skills and AI-powered content enrichment.
375
376
```python { .api }
377
# Base skill class
378
class SearchIndexerSkill:
379
"""Base class for indexer skills."""
380
odata_type: str
381
name: Optional[str] = None
382
description: Optional[str] = None
383
context: Optional[str] = None
384
inputs: List[InputFieldMappingEntry]
385
outputs: List[OutputFieldMappingEntry]
386
387
# Field mapping entries
388
class InputFieldMappingEntry:
389
"""Input field mapping for skills."""
390
name: str
391
source: str
392
source_context: Optional[str] = None
393
inputs: Optional[List["InputFieldMappingEntry"]] = None
394
395
class OutputFieldMappingEntry:
396
"""Output field mapping for skills."""
397
name: str
398
target_name: str
399
400
# Cognitive skills
401
class EntityRecognitionSkill(SearchIndexerSkill):
402
"""Entity recognition skill."""
403
odata_type: str = "#Microsoft.Skills.Text.EntityRecognitionSkill"
404
categories: Optional[List[str]] = None
405
default_language_code: Optional[str] = None
406
include_typeless_entities: Optional[bool] = None
407
minimum_precision: Optional[float] = None
408
409
class KeyPhraseExtractionSkill(SearchIndexerSkill):
410
"""Key phrase extraction skill."""
411
odata_type: str = "#Microsoft.Skills.Text.KeyPhraseExtractionSkill"
412
default_language_code: Optional[str] = None
413
max_key_phrase_count: Optional[int] = None
414
415
class LanguageDetectionSkill(SearchIndexerSkill):
416
"""Language detection skill."""
417
odata_type: str = "#Microsoft.Skills.Text.LanguageDetectionSkill"
418
419
class SentimentSkill(SearchIndexerSkill):
420
"""Sentiment analysis skill."""
421
odata_type: str = "#Microsoft.Skills.Text.SentimentSkill"
422
default_language_code: Optional[str] = None
423
model_version: Optional[SentimentSkillVersion] = None
424
425
class SentimentSkillVersion(str, Enum):
426
"""Sentiment skill versions."""
427
VERSION_1 = "1"
428
VERSION_3 = "3"
429
430
class OcrSkill(SearchIndexerSkill):
431
"""OCR text extraction skill."""
432
odata_type: str = "#Microsoft.Skills.Vision.OcrSkill"
433
text_extraction_algorithm: Optional[str] = None
434
default_language_code: Optional[str] = None
435
should_detect_orientation: Optional[bool] = None
436
437
class ImageAnalysisSkill(SearchIndexerSkill):
438
"""Image analysis skill."""
439
odata_type: str = "#Microsoft.Skills.Vision.ImageAnalysisSkill"
440
default_language_code: Optional[str] = None
441
visual_features: Optional[List[VisualFeature]] = None
442
details: Optional[List[str]] = None
443
444
class VisualFeature(str, Enum):
445
"""Visual features for image analysis."""
446
ADULT = "adult"
447
BRANDS = "brands"
448
CATEGORIES = "categories"
449
COLOR = "color"
450
DESCRIPTION = "description"
451
FACES = "faces"
452
OBJECTS = "objects"
453
TAGS = "tags"
454
455
class WebApiSkill(SearchIndexerSkill):
456
"""Custom web API skill."""
457
odata_type: str = "#Microsoft.Skills.Custom.WebApiSkill"
458
uri: str
459
http_method: Optional[str] = None
460
http_headers: Optional[Dict[str, str]] = None
461
timeout: Optional[str] = None
462
batch_size: Optional[int] = None
463
degree_of_parallelism: Optional[int] = None
464
465
class AzureOpenAIEmbeddingSkill(SearchIndexerSkill):
466
"""Azure OpenAI embedding skill."""
467
odata_type: str = "#Microsoft.Skills.Text.AzureOpenAIEmbeddingSkill"
468
resource_uri: Optional[str] = None
469
api_key: Optional[str] = None
470
deployment_id: Optional[str] = None
471
model_name: Optional[AzureOpenAIModelName] = None
472
dimensions: Optional[int] = None
473
474
# Utility skills
475
class ConditionalSkill(SearchIndexerSkill):
476
"""Conditional logic skill."""
477
odata_type: str = "#Microsoft.Skills.Util.ConditionalSkill"
478
479
class DocumentExtractionSkill(SearchIndexerSkill):
480
"""Document extraction skill."""
481
odata_type: str = "#Microsoft.Skills.Util.DocumentExtractionSkill"
482
parsing_mode: Optional[str] = None
483
data_to_extract: Optional[str] = None
484
configuration: Optional[Dict[str, Any]] = None
485
486
class MergeSkill(SearchIndexerSkill):
487
"""Text merging skill."""
488
odata_type: str = "#Microsoft.Skills.Text.MergeSkill"
489
insert_pre_tag: Optional[str] = None
490
insert_post_tag: Optional[str] = None
491
492
class ShaperSkill(SearchIndexerSkill):
493
"""Data shaping skill."""
494
odata_type: str = "#Microsoft.Skills.Util.ShaperSkill"
495
496
class SplitSkill(SearchIndexerSkill):
497
"""Text splitting skill."""
498
odata_type: str = "#Microsoft.Skills.Text.SplitSkill"
499
text_split_mode: Optional[TextSplitMode] = None
500
maximum_page_length: Optional[int] = None
501
default_language_code: Optional[str] = None
502
503
class TextSplitMode(str, Enum):
504
"""Text splitting modes."""
505
PAGES = "pages"
506
SENTENCES = "sentences"
507
508
class TextTranslationSkill(SearchIndexerSkill):
509
"""Text translation skill."""
510
odata_type: str = "#Microsoft.Skills.Text.TranslationSkill"
511
default_to_language_code: str
512
default_from_language_code: Optional[str] = None
513
suggested_from: Optional[TextTranslationSkillLanguage] = None
514
515
class TextTranslationSkillLanguage(str, Enum):
516
"""Translation language codes."""
517
EN = "en"
518
ES = "es"
519
FR = "fr"
520
DE = "de"
521
# ... additional language codes
522
```
523
524
### Analyzer and Text Processing Models
525
526
Types for configuring text analysis, tokenization, and linguistic processing.
527
528
```python { .api }
529
# Analyzer types
530
class LexicalAnalyzer:
531
"""Base analyzer class."""
532
odata_type: str
533
name: str
534
535
class StandardAnalyzer(LexicalAnalyzer):
536
"""Standard Lucene analyzer."""
537
odata_type: str = "#Microsoft.Azure.Search.StandardAnalyzer"
538
max_token_length: Optional[int] = None
539
stopwords: Optional[List[str]] = None
540
541
class StopAnalyzer(LexicalAnalyzer):
542
"""Stop word analyzer."""
543
odata_type: str = "#Microsoft.Azure.Search.StopAnalyzer"
544
stopwords: Optional[List[str]] = None
545
546
class PatternAnalyzer(LexicalAnalyzer):
547
"""Pattern-based analyzer."""
548
odata_type: str = "#Microsoft.Azure.Search.PatternAnalyzer"
549
pattern: Optional[str] = None
550
flags: Optional[str] = None
551
stopwords: Optional[List[str]] = None
552
553
class CustomAnalyzer(LexicalAnalyzer):
554
"""Custom analyzer definition."""
555
odata_type: str = "#Microsoft.Azure.Search.CustomAnalyzer"
556
tokenizer_name: str
557
token_filters: Optional[List[str]] = None
558
char_filters: Optional[List[str]] = None
559
560
# Tokenizers
561
class LexicalTokenizer:
562
"""Base tokenizer class."""
563
odata_type: str
564
name: str
565
566
class StandardTokenizer(LexicalTokenizer):
567
"""Standard Lucene tokenizer."""
568
odata_type: str = "#Microsoft.Azure.Search.StandardTokenizer"
569
max_token_length: Optional[int] = None
570
571
class KeywordTokenizer(LexicalTokenizer):
572
"""Keyword tokenizer."""
573
odata_type: str = "#Microsoft.Azure.Search.KeywordTokenizer"
574
buffer_size: Optional[int] = None
575
576
# Token filters
577
class TokenFilter:
578
"""Base token filter class."""
579
odata_type: str
580
name: str
581
582
class LowercaseTokenFilter(TokenFilter):
583
"""Lowercase token filter."""
584
odata_type: str = "#Microsoft.Azure.Search.LowercaseTokenFilter"
585
586
class StopwordsTokenFilter(TokenFilter):
587
"""Stop words token filter."""
588
odata_type: str = "#Microsoft.Azure.Search.StopwordsTokenFilter"
589
stopwords: Optional[List[str]] = None
590
stopwords_list: Optional[StopwordsList] = None
591
ignore_case: Optional[bool] = None
592
remove_trailing: Optional[bool] = None
593
594
class StopwordsList(str, Enum):
595
"""Predefined stopwords lists."""
596
ARABIC = "arabic"
597
ARMENIAN = "armenian"
598
BASQUE = "basque"
599
BRAZILIAN = "brazilian"
600
BULGARIAN = "bulgarian"
601
CATALAN = "catalan"
602
CZECH = "czech"
603
DANISH = "danish"
604
DUTCH = "dutch"
605
ENGLISH = "english"
606
FINNISH = "finnish"
607
FRENCH = "french"
608
GALICIAN = "galician"
609
GERMAN = "german"
610
GREEK = "greek"
611
HINDI = "hindi"
612
HUNGARIAN = "hungarian"
613
INDONESIAN = "indonesian"
614
IRISH = "irish"
615
ITALIAN = "italian"
616
LATVIAN = "latvian"
617
NORWEGIAN = "norwegian"
618
PERSIAN = "persian"
619
PORTUGUESE = "portuguese"
620
ROMANIAN = "romanian"
621
RUSSIAN = "russian"
622
SORANI = "sorani"
623
SPANISH = "spanish"
624
SWEDISH = "swedish"
625
THAI = "thai"
626
TURKISH = "turkish"
627
628
# Character filters
629
class CharFilter:
630
"""Base character filter class."""
631
odata_type: str
632
name: str
633
634
class MappingCharFilter(CharFilter):
635
"""Character mapping filter."""
636
odata_type: str = "#Microsoft.Azure.Search.MappingCharFilter"
637
mappings: List[str]
638
639
class PatternReplaceCharFilter(CharFilter):
640
"""Pattern replacement character filter."""
641
odata_type: str = "#Microsoft.Azure.Search.PatternReplaceCharFilter"
642
pattern: str
643
replacement: str
644
```
645
646
### Similarity and Scoring Models
647
648
Types for configuring search result ranking and similarity algorithms.
649
650
```python { .api }
651
# Similarity algorithms
652
class SimilarityAlgorithm:
653
"""Base similarity algorithm."""
654
odata_type: str
655
656
class BM25SimilarityAlgorithm(SimilarityAlgorithm):
657
"""BM25 similarity algorithm."""
658
odata_type: str = "#Microsoft.Azure.Search.BM25Similarity"
659
k1: Optional[float] = None
660
b: Optional[float] = None
661
662
class ClassicSimilarityAlgorithm(SimilarityAlgorithm):
663
"""Classic TF-IDF similarity."""
664
odata_type: str = "#Microsoft.Azure.Search.ClassicSimilarity"
665
666
# Scoring profiles
667
class ScoringProfile:
668
"""Custom scoring profile."""
669
name: str
670
text_weights: Optional[TextWeights] = None
671
functions: Optional[List[ScoringFunction]] = None
672
function_aggregation: Optional[FunctionAggregation] = None
673
674
class TextWeights:
675
"""Text field weights for scoring."""
676
weights: Dict[str, float]
677
678
class FunctionAggregation(str, Enum):
679
"""Function aggregation modes."""
680
SUM = "sum"
681
AVERAGE = "average"
682
MINIMUM = "minimum"
683
MAXIMUM = "maximum"
684
FIRST_MATCHING = "firstMatching"
685
686
# Scoring functions
687
class ScoringFunction:
688
"""Base scoring function."""
689
type: str
690
field_name: str
691
boost: float
692
interpolation: Optional[str] = None
693
694
class DistanceScoringFunction(ScoringFunction):
695
"""Distance-based scoring function."""
696
type: str = "distance"
697
distance: DistanceScoringParameters
698
699
class FreshnessScoringFunction(ScoringFunction):
700
"""Freshness-based scoring function."""
701
type: str = "freshness"
702
freshness: FreshnessScoringParameters
703
704
class MagnitudeScoringFunction(ScoringFunction):
705
"""Magnitude-based scoring function."""
706
type: str = "magnitude"
707
magnitude: MagnitudeScoringParameters
708
709
class TagScoringFunction(ScoringFunction):
710
"""Tag-based scoring function."""
711
type: str = "tag"
712
tag: TagScoringParameters
713
```
714
715
## Usage Examples
716
717
### Custom Field Types
718
719
```python
720
from azure.search.documents.indexes.models import SearchField, SearchFieldDataType
721
722
# Vector field for embeddings
723
vector_field = SearchField(
724
name="content_vector",
725
type=SearchFieldDataType.Collection(SearchFieldDataType.Single),
726
vector_search_dimensions=1536,
727
vector_search_profile_name="my-vector-config"
728
)
729
730
# Complex type with nested fields
731
address_field = ComplexField(
732
name="address",
733
fields=[
734
SimpleField("street", SearchFieldDataType.String),
735
SimpleField("city", SearchFieldDataType.String, filterable=True),
736
SimpleField("zipCode", SearchFieldDataType.String, filterable=True)
737
]
738
)
739
740
# Collection of complex types
741
addresses_field = ComplexField(
742
name="addresses",
743
collection=True,
744
fields=[
745
SimpleField("type", SearchFieldDataType.String),
746
SimpleField("street", SearchFieldDataType.String),
747
SimpleField("city", SearchFieldDataType.String)
748
]
749
)
750
```
751
752
### Search Query Configuration
753
754
```python
755
from azure.search.documents.models import QueryType, SearchMode, VectorizedQuery
756
757
# Semantic search query
758
results = client.search(
759
search_text="find documents about machine learning",
760
query_type=QueryType.SEMANTIC,
761
semantic_configuration_name="my-semantic-config",
762
query_answer="extractive",
763
query_caption="extractive",
764
top=10
765
)
766
767
# Hybrid vector + text search
768
vector_query = VectorizedQuery(
769
vector=[0.1, 0.2, 0.3, ...],
770
k_nearest_neighbors=5,
771
fields="content_vector"
772
)
773
774
results = client.search(
775
search_text="machine learning algorithms",
776
vector_queries=[vector_query],
777
search_mode=SearchMode.ALL,
778
top=20
779
)
780
```
781
782
### Document Operations
783
784
```python
785
from azure.search.documents import IndexDocumentsBatch
786
from azure.search.documents.models import IndexAction
787
788
# Create batch with mixed operations
789
batch = IndexDocumentsBatch()
790
791
# Add documents
792
batch.add_upload_actions([
793
{"id": "1", "title": "New Document", "content": "Content here"}
794
])
795
796
# Update documents
797
batch.add_merge_actions([
798
{"id": "2", "title": "Updated Title"}
799
])
800
801
# Delete documents
802
batch.add_delete_actions([
803
{"id": "3"}
804
])
805
806
# Execute batch
807
results = client.index_documents(batch)
808
for result in results:
809
if result.succeeded():
810
print(f"Document {result.key} processed successfully")
811
else:
812
print(f"Error processing {result.key}: {result.error_message}")
813
```