Share via

how to start AI in .net?

mc 6,901 Reputation points
2026-04-26T01:01:01.8733333+00:00

1.I have several books and I want the AI train with the books and only the books.

2.Then I will get model and I can put the model in my MAUI and then I can ask questions about the books.

I have searched the github and find two lib:1.OpenAI.Net and Microsoft.Extensions.AI.AbStractions.

can you tell me how to start it? Which repo I should use?

Developer technologies | .NET | .NET Machine Learning
Developer technologies | .NET | .NET Machine Learning

.NET: Microsoft Technologies based on the .NET software framework. Machine learning: A type of artificial intelligence focused on enabling computers to use observed data to evolve new behaviors that have not been explicitly programmed.

0 comments No comments

Answer accepted by question author

  1. Jack Dang (WICLOUD CORPORATION) 17,585 Reputation points Microsoft External Staff Moderator
    2026-04-27T03:45:05.8233333+00:00

    Hi @mc ,

    Thanks for reaching out.

    I would start with Microsoft.Extensions.AI as the main foundation. It gives you a clean .NET abstraction for chat and embeddings, and it keeps things flexible if you want to switch between OpenAI, Azure OpenAI, or another provider later.

    For the overall approach, I would not start with model training. The more suitable path is to use an existing model with a retrieval flow, where you chunk your book content, create embeddings, store them, and then retrieve the most relevant passages when a user asks a question.

    The approachable way to begin is with a small prototype first, ideally outside of MAUI, just to validate the ingestion, embeddings, retrieval, and answer generation flow. Once that is working, you can plug the same pipeline into your MAUI app much more easily.

    So if you are deciding which repo or package to use first, I would use Microsoft.Extensions.AI and treat provider-specific SDKs like OpenAI.Net as implementation details underneath it.

    Hope this helps! If my answer was helpful, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-04-26T01:01:33.93+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Use the .NET AI abstractions and an OpenAI-compatible provider, then add vector search over the book content. A high-level path is:

    1. Learn the .NET AI stack
      • Start with the .NET AI overview to understand how Microsoft.Extensions.AI works and which providers are supported (OpenAI, Azure OpenAI, Ollama for local models, etc.).
      • The key abstraction is IChatClient from Microsoft.Extensions.AI.Abstractions, which lets code talk to different models without changing app logic.
    2. Build a simple chat app first
      • Follow the quickstarts that show how to connect to a model and send prompts using Microsoft.Extensions.AI:
        • “Connect to and prompt an AI model” quickstart.
        • “Build an AI chat app with .NET” quickstart.
      • These samples use:
        • Microsoft.Extensions.AI.OpenAI (for OpenAI or Azure OpenAI)
        • Azure.AI.OpenAI + Azure.Identity (for Azure OpenAI)
        • Or OpenAI (for OpenAI’s public endpoint)
      • This gives a working console chat app that can later be embedded in a MAUI app.
    3. Understand what “train with the books” means
      • For most .NET apps, instead of fully training a new model, use retrieval-augmented generation (RAG):
        • Store book content as vectors (embeddings) in a vector store.
        • At question time, search the vector store for relevant passages.
        • Send those passages plus the user’s question to the model via IChatClient.
      • This approach uses existing models (OpenAI, Azure OpenAI, or local models via Ollama) and focuses on indexing the books.
    4. Create embeddings for the books
      • Use an embedding-capable model via Microsoft.Extensions.AI abstractions (for example, an Azure OpenAI embedding model through Azure.AI.OpenAI or OpenAI’s embeddings via the OpenAI SDK).
      • The Microsoft.Extensions.AI.Abstractions package defines IEmbeddingGenerator<TInput,TEmbedding> for this purpose.
      • Steps:
        1. Split each book into chunks (e.g., paragraphs or pages).
        2. Call the embedding generator for each chunk.
        3. Store (chunkText, embeddingVector, metadata) in a vector store (SQL with vector support, a dedicated vector DB, or a custom store).
    5. Build a vector-search app in .NET
      • Use the “Chat with your data” guidance (vector search app) to see how to:
        • Build a vector search pipeline.
        • Combine retrieved text with a chat prompt.
      • The pattern is:
        1. User asks a question in MAUI.
        2. Backend (or local service) computes an embedding for the question.
        3. Perform vector similarity search over the stored book embeddings.
        4. Take the top N relevant passages and construct a prompt.
        5. Call IChatClient with that prompt and return the answer.
    6. Integrate with .NET MAUI
      • Keep AI logic in a .NET library or backend service that uses Microsoft.Extensions.AI.
      • MAUI app calls into that library/service:
        • Send user question.
        • Receive answer and display it.
      • Because Microsoft.Extensions.AI uses abstractions, the underlying provider (OpenAI, Azure OpenAI, Ollama, etc.) can be swapped with minimal code changes.
    7. Which library to use
      • Prefer the official abstractions and SDKs:
        • Microsoft.Extensions.AI and Microsoft.Extensions.AI.Abstractions for the AI pipeline and DI/middleware.
        • Microsoft.Extensions.AI.OpenAI plus either Azure.AI.OpenAI (for Azure OpenAI) or OpenAI (for OpenAI’s public API) as the provider.
      • This combination is recommended in the .NET AI docs and integrates cleanly with other .NET components.
    8. Next learning steps
      • Follow this order:
        1. Read “Develop .NET apps with AI features” overview.
        2. Do the “Build an Azure AI chat app with .NET” quickstart.
        3. Do the “Connect to and prompt an AI model” quickstart.
        4. Then follow “Get insight about your data from a .NET Azure AI chat app” (vector search) to adapt it for books.

    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.