DEV Community

Johnny Z
Johnny Z

Posted on • Edited on

Kernel Memory with Azure OpenAI, Blob storage and AI Search services

Kernel Memory with Azure OpenAI,
Blob storage and AI Search.

Azure Open AI

On AzureOpenAI resource, deploy gpt-4 chat completion model and text-embedding-ada-002 embedding model

var builder = new KernelMemoryBuilder()
    .WithAzureOpenAITextGeneration(
        new AzureOpenAIConfig
        {
            Auth = AzureOpenAIConfig.AuthTypes.APIKey,
            APIKey = "Your AzureOpenAI api key",
            Endpoint = "https://your-azure-open-ai-resource-name.openai.azure.com",
            Deployment = "gpt-4"
        })
    .WithAzureOpenAITextEmbeddingGeneration(
        new AzureOpenAIConfig
        {
            Auth = AzureOpenAIConfig.AuthTypes.APIKey,
            APIKey = "Your AzureOpenAI api key",
            Endpoint = "https://your-azure-open-ai-resource-name.openai.azure.com",
            Deployment = "text-embedding-ada-002"
        });
Enter fullscreen mode Exit fullscreen mode

Azure storage account

Azure blob storage to store kenerl memory pipeline artifacts

var builder = new KernelMemoryBuilder()
    .WithAzureBlobsDocumentStorage(
        new AzureBlobsConfig
        {
            Account = "your-blob-storage-account",
            Auth = AzureBlobsConfig.AuthTypes.AccountKey,
            AccountKey = "your-blob-account-key",
            Container = "document-ingestion"
        })
Enter fullscreen mode Exit fullscreen mode

Azure AI Search service

Azure AI search service as vector databases

var builder = new KernelMemoryBuilder()
    .WithAzureAISearchMemoryDb(
        new AzureAISearchConfig
        {
            Endpoint = "https://your-search-service-resource-name.search.windows.net",
            Auth = AzureAISearchConfig.AuthTypes.APIKey,
            APIKey = "your search service api key"
        })
Enter fullscreen mode Exit fullscreen mode

Import some document and ask questions

await kernelMemory.ImportDocumentAsync(
    filePath: "resources/earth_book_2019_tagged.pdf",
    documentId: "earth_book_2019",
    index: "books");

var response =
    await kernelMemory.AskAsync(
        "Where is Amazon rainforest on earth?", 
        index: "books");    

Enter fullscreen mode Exit fullscreen mode

Note the index name "books", kernel memory automatically creates Azure AI Search index name "books" if it does not exist and "books" folder in the blob container.

Sample code here

Please feel free to reach out on twitter @roamingcode

Image of Datadog

Measure and Advance Your DevSecOps Maturity

In this white paper, we lay out a DevSecOps maturity model based on our experience helping thousands of organizations advance their DevSecOps practices. Learn the key competencies and practices across four distinct levels of maturity.

Get The White Paper

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay