Skip to content

Latest commit

 

History

History
178 lines (135 loc) · 11.1 KB

functions-bindings-openai-semanticsearch-input.md

File metadata and controls

178 lines (135 loc) · 11.1 KB
titledescriptionms.topicms.customms.collectionms.datezone_pivot_groups
Azure OpenAI Semantic Search Input Binding for Azure Functions
Learn how to use the Azure OpenAI semantic search input binding to use semantic search on your embeddings during function execution in Azure Functions.
reference
build-2024
devx-track-extended-java
devx-track-js
devx-track-python
devx-track-ts
ce-skilling-ai-copilot
01/07/2025
programming-languages-set-functions

Azure OpenAI Semantic Search Input Binding for Azure Functions

[!INCLUDE preview-support]

The Azure OpenAI semantic search input binding allows you to use semantic search on your embeddings.

For information on setup and configuration details of the Azure OpenAI extension, see Azure OpenAI extensions for Azure Functions. To learn more about semantic ranking in Azure AI Search, see Semantic ranking in Azure AI Search.

[!INCLUDE functions-support-notes-samples-openai]

Example

::: zone pivot="programming-language-csharp"
This example shows how to perform a semantic search on a file.

:::code language="csharp" source="~/functions-openai-extension/samples/rag-aisearch/csharp-ooproc/FilePrompt.cs" range="63-70":::

::: zone-end
::: zone pivot="programming-language-java" This example shows how to perform a semantic search on a file.

:::code language="java" source="~/functions-openai-extension/samples/rag-aisearch/java/src/main/java/com/azfs/FilePrompt.java" range="70-84":::

::: zone-end
::: zone pivot="programming-language-javascript,programming-language-typescript" This example shows how to perform a semantic search on a file. ::: zone-end
::: zone pivot="programming-language-javascript"

:::code language="javascript" source="~/functions-openai-extension/samples/rag-aisearch/javascript/src/app.js" range="39-57":::

::: zone-end
::: zone pivot="programming-language-typescript"

:::code language="typescript" source="~/functions-openai-extension/samples/rag-aisearch/typescript/src/app.ts" range="42-60":::

::: zone-end
::: zone pivot="programming-language-powershell"

This example shows how to perform a semantic search on a file.

Here's the function.json file for prompting a file:

:::code language="json" source="~/functions-openai-extension/samples/rag-aisearch/powershell/PromptFile/function.json" :::

For more information about function.json file properties, see the Configuration section.

:::code language="powershell" source="~/functions-openai-extension/samples/rag-aisearch/powershell/PromptFile/run.ps1" :::

::: zone-end
::: zone pivot="programming-language-python"
[!INCLUDE functions-examples-not-available-note]

::: zone-end

::: zone pivot="programming-language-csharp"

Attributes

Apply the SemanticSearchInput attribute to define a semantic search input binding, which supports these parameters:

ParameterDescription
ConnectionNameThe name of an app setting or environment variable that contains the connection string value. This property supports binding expressions.
CollectionThe name of the collection or table or index to search. This property supports binding expressions.
QueryThe semantic query text to use for searching. This property supports binding expressions.
EmbeddingsModelThe ID of the model to use for embeddings. The default value is text-embedding-3-small. This property supports binding expressions.
ChatModelGets or sets the name of the Large Language Model to invoke for chat responses. The default value is gpt-3.5-turbo. This property supports binding expressions.
SystemPromptOptional. Gets or sets the system prompt to use for prompting the large language model. The system prompt is appended with knowledge that is fetched as a result of the Query. The combined prompt is sent to the OpenAI Chat API. This property supports binding expressions.
MaxKnowledgeCountOptional. Gets or sets the number of knowledge items to inject into the SystemPrompt.

::: zone-end ::: zone pivot="programming-language-java"

Annotations

The SemanticSearchInput annotation enables you to define a semantic search input binding, which supports these parameters:

ElementDescription
nameGets or sets the name of the input binding.
connectionNameThe name of an app setting or environment variable that contains the connection string value. This property supports binding expressions.
collectionThe name of the collection or table or index to search. This property supports binding expressions.
queryThe semantic query text to use for searching. This property supports binding expressions.
embeddingsModelThe ID of the model to use for embeddings. The default value is text-embedding-3-small. This property supports binding expressions.
chatModelGets or sets the name of the Large Language Model to invoke for chat responses. The default value is gpt-3.5-turbo. This property supports binding expressions.
systemPromptOptional. Gets or sets the system prompt to use for prompting the large language model. The system prompt is appended with knowledge that is fetched as a result of the Query. The combined prompt is sent to the OpenAI Chat API. This property supports binding expressions.
maxKnowledgeCountOptional. Gets or sets the number of knowledge items to inject into the SystemPrompt.

::: zone-end
::: zone pivot="programming-language-python"

Decorators

During the preview, define the input binding as a generic_input_binding binding of type semanticSearch, which supports these parameters:

ParameterDescription
arg_nameThe name of the variable that represents the binding parameter.
connection_nameThe name of an app setting or environment variable that contains the connection string value. This property supports binding expressions.
collectionThe name of the collection or table or index to search. This property supports binding expressions.
queryThe semantic query text to use for searching. This property supports binding expressions.
embeddings_modelThe ID of the model to use for embeddings. The default value is text-embedding-3-small. This property supports binding expressions.
chat_modelGets or sets the name of the Large Language Model to invoke for chat responses. The default value is gpt-3.5-turbo. This property supports binding expressions.
system_promptOptional. Gets or sets the system prompt to use for prompting the large language model. The system prompt is appended with knowledge that is fetched as a result of the Query. The combined prompt is sent to the OpenAI Chat API. This property supports binding expressions.
max_knowledge_countOptional. Gets or sets the number of knowledge items to inject into the SystemPrompt.

::: zone-end ::: zone pivot="programming-language-powershell"

Configuration

The binding supports these configuration properties that you set in the function.json file.

PropertyDescription
typeMust be semanticSearch.
directionMust be in.
nameThe name of the input binding.
connectionNameGets or sets the name of an app setting or environment variable that contains a connection string value. This property supports binding expressions.
collectionThe name of the collection or table or index to search. This property supports binding expressions.
queryThe semantic query text to use for searching. This property supports binding expressions.
embeddingsModelThe ID of the model to use for embeddings. The default value is text-embedding-3-small. This property supports binding expressions.
chatModelGets or sets the name of the Large Language Model to invoke for chat responses. The default value is gpt-3.5-turbo. This property supports binding expressions.
systemPromptOptional. Gets or sets the system prompt to use for prompting the large language model. The system prompt is appended with knowledge that is fetched as a result of the Query. The combined prompt is sent to the OpenAI Chat API. This property supports binding expressions.
maxKnowledgeCountOptional. Gets or sets the number of knowledge items to inject into the SystemPrompt.

::: zone-end
::: zone pivot="programming-language-javascript,programming-language-typescript"

Configuration

The binding supports these properties, which are defined in your code:

PropertyDescription
connectionNameThe name of an app setting or environment variable that contains the connection string value. This property supports binding expressions.
collectionThe name of the collection or table or index to search. This property supports binding expressions.
queryThe semantic query text to use for searching. This property supports binding expressions.
embeddingsModelThe ID of the model to use for embeddings. The default value is text-embedding-3-small. This property supports binding expressions.
chatModelGets or sets the name of the Large Language Model to invoke for chat responses. The default value is gpt-3.5-turbo. This property supports binding expressions.
systemPromptOptional. Gets or sets the system prompt to use for prompting the large language model. The system prompt is appended with knowledge that is fetched as a result of the Query. The combined prompt is sent to the OpenAI Chat API. This property supports binding expressions.
maxKnowledgeCountOptional. Gets or sets the number of knowledge items to inject into the SystemPrompt.

::: zone-end

Usage

See the Example section for complete examples.

Related content

close