|
2 | 2 |
|
3 | 3 |
|
4 | 4 | import asyncio
|
5 |
| -from collections.abc import Coroutine |
| 5 | +from collections.abc import Awaitable, Callable |
6 | 6 | from typing import Any
|
7 | 7 |
|
| 8 | +from step_0_data_model import HotelSampleClass |
| 9 | + |
| 10 | +from semantic_kernel import Kernel |
| 11 | +from semantic_kernel.connectors.ai import FunctionChoiceBehavior |
| 12 | +from semantic_kernel.connectors.ai.open_ai import ( |
| 13 | + OpenAIChatCompletion, |
| 14 | + OpenAIChatPromptExecutionSettings, |
| 15 | + OpenAITextEmbedding, |
| 16 | +) |
| 17 | +from semantic_kernel.connectors.memory.azure_ai_search import AzureAISearchCollection |
| 18 | +from semantic_kernel.contents import ChatHistory |
| 19 | + |
8 | 20 | ###
|
9 | 21 | # The data model used for this sample is based on the hotel data model from the Azure AI Search samples.
|
10 | 22 | # When deploying a new index in Azure AI Search using the import wizard you can choose to deploy the 'hotel-samples'
|
|
16 | 28 | # This sample assumes the index is deployed, and the vectors have been filled.
|
17 | 29 | # Use the step_1_interact_with_the_collection.py sample, with `first_run = True` to fill the vectors.
|
18 | 30 | ###
|
19 |
| -from step_0_data_model import HotelSampleClass |
20 |
| - |
21 |
| -from semantic_kernel import Kernel |
22 |
| -from semantic_kernel.connectors.ai.function_choice_behavior import FunctionChoiceBehavior |
23 |
| -from semantic_kernel.connectors.ai.open_ai import ( |
24 |
| - OpenAIChatCompletion, |
25 |
| - OpenAIChatPromptExecutionSettings, |
26 |
| - OpenAITextEmbedding, |
27 |
| -) |
28 |
| -from semantic_kernel.connectors.memory.azure_ai_search import AzureAISearchCollection |
29 |
| -from semantic_kernel.contents import ChatHistory |
30 | 31 | from semantic_kernel.data import (
|
31 | 32 | VectorSearchFilter,
|
32 | 33 | VectorSearchOptions,
|
33 |
| - VectorStoreRecordUtils, |
34 | 34 | )
|
35 |
| -from semantic_kernel.data.search_options import SearchOptions |
36 |
| -from semantic_kernel.data.text_search.vector_store_text_search import VectorStoreTextSearch |
37 |
| -from semantic_kernel.filters.filter_types import FilterTypes |
38 |
| -from semantic_kernel.filters.functions.function_invocation_context import FunctionInvocationContext |
| 35 | +from semantic_kernel.data.text_search import SearchOptions |
| 36 | +from semantic_kernel.filters import FilterTypes, FunctionInvocationContext |
39 | 37 | from semantic_kernel.functions import (
|
40 | 38 | KernelArguments,
|
41 | 39 | KernelParameterMetadata,
|
|
50 | 48 | kernel.add_service(OpenAIChatCompletion(service_id=service_id))
|
51 | 49 | embeddings = OpenAITextEmbedding(service_id="embedding", ai_model_id="text-embedding-3-small")
|
52 | 50 | kernel.add_service(embeddings)
|
53 |
| -vectorizer = VectorStoreRecordUtils(kernel) |
54 | 51 |
|
55 | 52 | # Create a Text Search object, with a Azure AI Search collection.
|
56 | 53 | # using the `from_vector_text_search` method means that this plugin will only use text search.
|
57 | 54 | # You can also choose to use the `from_vectorized_search` method to use vector search.
|
58 | 55 | # Or the `from_vectorizable_text_search` method if the collection is setup to vectorize incoming texts.
|
59 |
| -text_search = VectorStoreTextSearch.from_vector_text_search( |
60 |
| - AzureAISearchCollection[HotelSampleClass](collection_name=COLLECTION_NAME, data_model_type=HotelSampleClass) |
| 56 | +collection = AzureAISearchCollection[str, HotelSampleClass]( |
| 57 | + collection_name=COLLECTION_NAME, data_model_type=HotelSampleClass |
61 | 58 | )
|
| 59 | +text_search = collection.create_text_search_from_vector_text_search() |
62 | 60 |
|
63 | 61 |
|
64 | 62 | # Before we create the plugin, we want to create a function that will help the plugin work the way we want it to.
|
@@ -195,7 +193,9 @@ def update_options_search(
|
195 | 193 | # This allows us to see what parameters are being passed to the plugin.
|
196 | 194 | # And this gives us a way to debug the search experience and if necessary tweak the parameters and descriptions.
|
197 | 195 | @kernel.filter(filter_type=FilterTypes.FUNCTION_INVOCATION)
|
198 |
| -async def log_search_filter(context: FunctionInvocationContext, next: Coroutine[FunctionInvocationContext, Any, None]): |
| 196 | +async def log_search_filter( |
| 197 | + context: FunctionInvocationContext, next: Callable[[FunctionInvocationContext], Awaitable[None]] |
| 198 | +): |
199 | 199 | if context.function.plugin_name == "azure_ai_search":
|
200 | 200 | print(f"Calling Azure AI Search ({context.function.name}) with arguments:")
|
201 | 201 | for arg in context.arguments:
|
|
0 commit comments