Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 69 additions & 28 deletions sdk/search/azure-search-documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ to get started exploring APIs, but it should be managed carefully.*

To instantiate the `SearchClient`, you'll need the **endpoint**, **API key** and **index name**:

<!-- SNIPPET:sample_authentication.create_search_client_with_key -->
<!-- SNIPPET:sample_authentication.authenticate_search_client_with_api_key -->

```python
from azure.core.credentials import AzureKeyCredential
Expand Down Expand Up @@ -170,7 +170,7 @@ To learn more about semantic ranking, you can refer to the [documentation](https

**Vector search** is an information retrieval technique that uses numeric representations of searchable documents and query strings. By searching for numeric representations of content that are most similar to the numeric query, vector search can find relevant matches, even if the exact terms of the query are not present in the index. Moreover, vector search can be applied to various types of content, including images and videos and translated text, not just same-language text.

To learn how to index vector fields and perform vector search, you can refer to the [sample](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/search/azure-search-documents/samples/sample_vector_search.py). This sample provides detailed guidance on indexing vector fields and demonstrates how to perform vector search.
To learn how to index vector fields and perform vector search, you can refer to the [sample](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/search/azure-search-documents/samples/sample_query_vector.py). This sample provides detailed guidance on indexing vector fields and demonstrates how to perform vector search.

Additionally, for more comprehensive information about vector search, including its concepts and usage, you can refer to the [documentation](https://learn.microsoft.com/azure/search/vector-search-overview). The documentation provides in-depth explanations and guidance on leveraging the power of vector search in Azure AI Search.

Expand Down Expand Up @@ -231,30 +231,49 @@ You can use the `SearchIndexClient` to create a search index. Fields can be
defined using convenient `SimpleField`, `SearchableField`, or `ComplexField`
models. Indexes can also define suggesters, lexical analyzers, and more.

<!-- SNIPPET:sample_index_crud_operations.create_index -->
<!-- SNIPPET:sample_index_crud.create_index -->

```python
client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
name = "hotels"
from azure.core.credentials import AzureKeyCredential
from azure.search.documents.indexes import SearchIndexClient
from azure.search.documents.indexes.models import (
ComplexField,
CorsOptions,
SearchIndex,
ScoringProfile,
SearchFieldDataType,
SimpleField,
SearchableField,
)

index_client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
fields = [
SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True),
SimpleField(name="hotelName", type=SearchFieldDataType.String, searchable=True),
SimpleField(name="baseRate", type=SearchFieldDataType.Double),
SearchableField(name="description", type=SearchFieldDataType.String, collection=True),
SimpleField(name="HotelId", type=SearchFieldDataType.String, key=True),
SimpleField(name="HotelName", type=SearchFieldDataType.String, searchable=True),
SimpleField(name="BaseRate", type=SearchFieldDataType.Double),
SearchableField(
name="Description", type=SearchFieldDataType.String, collection=True
),
ComplexField(
name="address",
name="Address",
fields=[
SimpleField(name="streetAddress", type=SearchFieldDataType.String),
SimpleField(name="city", type=SearchFieldDataType.String),
SimpleField(name="StreetAddress", type=SearchFieldDataType.String),
SimpleField(name="City", type=SearchFieldDataType.String),
],
collection=True,
),
]
cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60)
scoring_profiles: List[ScoringProfile] = []
index = SearchIndex(name=name, fields=fields, scoring_profiles=scoring_profiles, cors_options=cors_options)

result = client.create_index(index)
index = SearchIndex(
name=index_name,
fields=fields,
scoring_profiles=scoring_profiles,
cors_options=cors_options,
)

result = index_client.create_index(index)
print(f"Created: index '{result.name}'")
```

<!-- END SNIPPET -->
Expand All @@ -266,17 +285,38 @@ an index in a single batched request. There are
[a few special rules for merging](https://learn.microsoft.com/rest/api/searchservice/addupdate-or-delete-documents#document-actions)
to be aware of.

<!-- SNIPPET:sample_crud_operations.upload_document -->
<!-- SNIPPET:sample_documents_crud.upload_document -->

```python
DOCUMENT = {
"hotelId": "1000",
"hotelName": "Azure Inn",
from azure.core.credentials import AzureKeyCredential
from azure.search.documents import SearchClient

search_client = SearchClient(service_endpoint, index_name, AzureKeyCredential(key))

document = {
"HotelId": "100",
"HotelName": "Azure Sanctuary",
"Description": "A quiet retreat offering understated elegance and premium amenities.",
"Description_fr": "Meilleur hôtel en ville si vous aimez les hôtels de luxe.",
"Category": "Luxury",
"Tags": [
"pool",
"view",
"wifi",
"concierge",
"private beach",
"gourmet dining",
"spa",
],
"ParkingIncluded": False,
"LastRenovationDate": "2024-01-15T00:00:00+00:00",
"Rating": 5,
"Location": {"type": "Point", "coordinates": [-122.131577, 47.678581]},
}

result = search_client.upload_documents(documents=[DOCUMENT])
result = search_client.upload_documents(documents=[document])

print("Upload of new document succeeded: {}".format(result[0].succeeded))
print(f"Uploaded: document 100 (succeeded={result[0].succeeded})")
```

<!-- END SNIPPET -->
Expand Down Expand Up @@ -309,18 +349,19 @@ you can retrieve a specific document from your index if you already know the
key. You could get the key from a query, for example, and want to show more
information about it or navigate your customer to that document.

<!-- SNIPPET:sample_get_document.get_document -->
<!-- SNIPPET:sample_documents_crud.get_document -->

```python
from azure.core.credentials import AzureKeyCredential
from azure.search.documents import SearchClient

search_client = SearchClient(service_endpoint, index_name, AzureKeyCredential(key))

result = search_client.get_document(key="23")
result = search_client.get_document(key="100")

print("Details for hotel '23' are:")
print(" Name: {}".format(result["hotelName"]))
print("Result:")
print(f" HotelId: 100")
print(f" HotelName: {result['HotelName']}")
```

<!-- END SNIPPET -->
Expand All @@ -333,7 +374,7 @@ See
[azure-core documentation](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md#transport)
for more information.

<!-- SNIPPET:sample_simple_query_async.simple_query_async -->
<!-- SNIPPET:sample_query_simple_async.simple_query_async -->

```python
from azure.core.credentials import AzureKeyCredential
Expand All @@ -344,9 +385,9 @@ search_client = SearchClient(service_endpoint, index_name, AzureKeyCredential(ke
async with search_client:
results = await search_client.search(search_text="spa")

print("Hotels containing 'spa' in the name (or other fields):")
print("Results: hotels with 'spa'")
async for result in results:
print(" Name: {} (rating {})".format(result["hotelName"], result["rating"]))
print(f" HotelName: {result['HotelName']} (rating {result['Rating']})")
```

<!-- END SNIPPET -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class SearchClient(HeadersMixin):
.. admonition:: Example:

.. literalinclude:: ../samples/sample_authentication.py
:start-after: [START create_search_client_with_key]
:end-before: [END create_search_client_with_key]
:start-after: [START authenticate_search_client_with_api_key]
:end-before: [END authenticate_search_client_with_api_key]
:language: python
:dedent: 4
:caption: Creating the SearchClient with an API key.
Expand Down Expand Up @@ -130,7 +130,7 @@ def get_document(self, key: str, selected_fields: Optional[List[str]] = None, **

.. admonition:: Example:

.. literalinclude:: ../samples/sample_get_document.py
.. literalinclude:: ../samples/sample_documents_crud.py
:start-after: [START get_document]
:end-before: [END get_document]
:language: python
Expand Down Expand Up @@ -323,7 +323,7 @@ def search(

.. admonition:: Example:

.. literalinclude:: ../samples/sample_simple_query.py
.. literalinclude:: ../samples/sample_query_simple.py
:start-after: [START simple_query]
:end-before: [END simple_query]
:language: python
Expand All @@ -332,7 +332,7 @@ def search(

.. admonition:: Example:

.. literalinclude:: ../samples/sample_filter_query.py
.. literalinclude:: ../samples/sample_query_filter.py
:start-after: [START filter_query]
:end-before: [END filter_query]
:language: python
Expand All @@ -341,7 +341,7 @@ def search(

.. admonition:: Example:

.. literalinclude:: ../samples/sample_facet_query.py
.. literalinclude:: ../samples/sample_query_facets.py
:start-after: [START facet_query]
:end-before: [END facet_query]
:language: python
Expand Down Expand Up @@ -466,7 +466,7 @@ def suggest(

.. admonition:: Example:

.. literalinclude:: ../samples/sample_suggestions.py
.. literalinclude:: ../samples/sample_query_suggestions.py
:start-after: [START suggest_query]
:end-before: [END suggest_query]
:language: python
Expand Down Expand Up @@ -548,7 +548,7 @@ def autocomplete(

.. admonition:: Example:

.. literalinclude:: ../samples/sample_autocomplete.py
.. literalinclude:: ../samples/sample_query_autocomplete.py
:start-after: [START autocomplete_query]
:end-before: [END autocomplete_query]
:language: python
Expand Down Expand Up @@ -593,7 +593,7 @@ def upload_documents(self, documents: List[Dict], **kwargs: Any) -> List[Indexin

.. admonition:: Example:

.. literalinclude:: ../samples/sample_crud_operations.py
.. literalinclude:: ../samples/sample_documents_crud.py
:start-after: [START upload_document]
:end-before: [END upload_document]
:language: python
Expand Down Expand Up @@ -627,7 +627,7 @@ def delete_documents(self, documents: List[Dict], **kwargs: Any) -> List[Indexin

.. admonition:: Example:

.. literalinclude:: ../samples/sample_crud_operations.py
.. literalinclude:: ../samples/sample_documents_crud.py
:start-after: [START delete_document]
:end-before: [END delete_document]
:language: python
Expand Down Expand Up @@ -657,7 +657,7 @@ def merge_documents(self, documents: List[Dict], **kwargs: Any) -> List[Indexing

.. admonition:: Example:

.. literalinclude:: ../samples/sample_crud_operations.py
.. literalinclude:: ../samples/sample_documents_crud.py
:start-after: [START merge_document]
:end-before: [END merge_document]
:language: python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class SearchClient(HeadersMixin):
.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_authentication_async.py
:start-after: [START create_search_client_with_key_async]
:end-before: [END create_search_client_with_key_async]
:start-after: [START authenticate_search_client_with_api_key_async]
:end-before: [END authenticate_search_client_with_api_key_async]
:language: python
:dedent: 4
:caption: Creating the SearchClient with an API key.
Expand Down Expand Up @@ -132,7 +132,7 @@ async def get_document(self, key: str, selected_fields: Optional[List[str]] = No

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_get_document_async.py
.. literalinclude:: ../samples/async_samples/sample_documents_crud_async.py
:start-after: [START get_document_async]
:end-before: [END get_document_async]
:language: python
Expand Down Expand Up @@ -327,7 +327,7 @@ async def search(

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_simple_query_async.py
.. literalinclude:: ../samples/async_samples/sample_query_simple_async.py
:start-after: [START simple_query_async]
:end-before: [END simple_query_async]
:language: python
Expand All @@ -336,7 +336,7 @@ async def search(

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_filter_query_async.py
.. literalinclude:: ../samples/async_samples/sample_query_filter_async.py
:start-after: [START filter_query_async]
:end-before: [END filter_query_async]
:language: python
Expand All @@ -345,7 +345,7 @@ async def search(

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_facet_query_async.py
.. literalinclude:: ../samples/async_samples/sample_query_facets_async.py
:start-after: [START facet_query_async]
:end-before: [END facet_query_async]
:language: python
Expand Down Expand Up @@ -463,7 +463,7 @@ async def suggest(

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_suggestions_async.py
.. literalinclude:: ../samples/async_samples/sample_query_suggestions_async.py
:start-after: [START suggest_query_async]
:end-before: [END suggest_query_async]
:language: python
Expand Down Expand Up @@ -545,7 +545,7 @@ async def autocomplete(

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_autocomplete_async.py
.. literalinclude:: ../samples/async_samples/sample_query_autocomplete_async.py
:start-after: [START autocomplete_query_async]
:end-before: [END autocomplete_query_async]
:language: python
Expand Down Expand Up @@ -590,7 +590,7 @@ async def upload_documents(self, documents: List[Dict], **kwargs: Any) -> List[I

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_crud_operations_async.py
.. literalinclude:: ../samples/async_samples/sample_documents_crud_async.py
:start-after: [START upload_document_async]
:end-before: [END upload_document_async]
:language: python
Expand Down Expand Up @@ -624,7 +624,7 @@ async def delete_documents(self, documents: List[Dict], **kwargs: Any) -> List[I

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_crud_operations_async.py
.. literalinclude:: ../samples/async_samples/sample_documents_crud_async.py
:start-after: [START delete_document_async]
:end-before: [END delete_document_async]
:language: python
Expand Down Expand Up @@ -654,7 +654,7 @@ async def merge_documents(self, documents: List[Dict], **kwargs: Any) -> List[In

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_crud_operations_async.py
.. literalinclude:: ../samples/async_samples/sample_documents_crud_async.py
:start-after: [START merge_document_async]
:end-before: [END merge_document_async]
:language: python
Expand Down
Loading