Python: extended notebook 06 to showcase Azure AI Search for semantic memory (#3573)

### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Sample notebook 06-memory-and-embeddings demonstrated how semantic
kernel lets users add memory to their kernels and also work around
ever-growing contexts that eventually exceed the maximum token limit. It
did so by using the in RAM VolatileMemoryStore and teased the
possibility of offloading this to an external vector store. With this
pull request, we want to provide guidance and repeatable steps so that
users can actually perform semantic search by leveraging an external
vector store, Azure AI Search (formerly known as Azure Cognitive Search

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

The changes consist in new cells added at the tail end of the existing
notebook. We register a new memory store, external this time and show
case how the rest of the code can be reused as-is. We add the capability
of providing access credentials to Azure AI Search in environment
variables as well.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Evan Mattson <[email protected]>
This commit is contained in:
rom212
2023-11-27 17:18:16 +00:00
committed by GitHub
co-authored by Evan Mattson
parent f2dd381eed
commit 712cbafa10
4 changed files with 141 additions and 7 deletions
+2
View File
@@ -15,6 +15,7 @@ from semantic_kernel.semantic_functions.semantic_function_config import (
)
from semantic_kernel.utils.null_logger import NullLogger
from semantic_kernel.utils.settings import (
azure_aisearch_settings_from_dot_env,
azure_cosmos_db_settings_from_dot_env,
azure_openai_settings_from_dot_env,
bing_search_settings_from_dot_env,
@@ -31,6 +32,7 @@ __all__ = [
"NullLogger",
"openai_settings_from_dot_env",
"azure_openai_settings_from_dot_env",
"azure_aisearch_settings_from_dot_env",
"postgres_settings_from_dot_env",
"pinecone_settings_from_dot_env",
"bing_search_settings_from_dot_env",
+17
View File
@@ -230,3 +230,20 @@ def redis_settings_from_dot_env() -> str:
), "Redis connection string not found in .env file"
return connection_string
def azure_aisearch_settings_from_dot_env() -> Tuple[str, str]:
"""
Reads the Azure AI Search environment variables for the .env file.
Returns:
Tuple[str, str]: Azure AI Search API key, the Azure AI Search URL
"""
config = dotenv_values(".env")
api_key = config.get("AZURE_AISEARCH_API_KEY", None)
url = config.get("AZURE_AISEARCH_URL", None)
assert url is not None, "Azure AI Search URL not found in .env file"
assert api_key is not None, "Azure AI Search API key not found in .env file"
return api_key, url