### Console Summary Example Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/QUANTIZATION_BENCHMARKS_QUICKSTART.md An example of the console summary output from the benchmarks. ```text BenchmarkDotNet v0.15.8 runtime=.NET 8.0.27, cpu=... | Method | Mean | Error | |-------------------------------|-----------|----------| | FullPrecision_SingleEmbedding | 45.23 ms | 0.81 ms | | Quantized_SingleEmbedding | 32.05 ms | 0.52 ms | ✅ 29% faster | FullPrecision_Batch32 | 1250 ms | 22 ms | | Quantized_Batch32 | 975 ms | 18 ms | ✅ 22% faster ``` -------------------------------- ### Quick Start Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/harrier-integration.md Instantiate the HarrierEmbeddingGenerator and generate embeddings for sample text. ```csharp using ElBruno.LocalEmbeddings.Harrier; using ElBruno.LocalEmbeddings.Harrier.Options; // Create with default settings (downloads quantized INT8 model on first run) await using var generator = await HarrierEmbeddingGenerator.CreateAsync(); // Generate embeddings var embeddings = await generator.GenerateAsync(["Hello world!", "Hola mundo!"]); Console.WriteLine($ ``` ```csharp Dimensions: {embeddings[0].Vector.Length} ``` -------------------------------- ### Example 1: Simple Usage Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/azure-hybrid-quickstart.md A basic C# example demonstrating how to generate embeddings for a list of texts. ```csharp var texts = new[] { "Python", "JavaScript", "C#" }; var result = await embeddingGenerator.GenerateAsync(texts); Console.WriteLine($"Generated {result.Count} embeddings"); ``` -------------------------------- ### Root README Quick Start Example Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/plans/plan_260212_1933_done.md Minimal 'hello world' code block for the root README, demonstrating basic usage of LocalEmbeddings. ```csharp using elbruno.LocalEmbeddings; var generator = new LocalEmbeddingGenerator(); var embedding = await generator.GenerateAsync("Hello world"); Console.WriteLine($"Embedding dimension: {embedding.Length}"); ``` -------------------------------- ### Dependency Injection Swap - Before (MiniLM) Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/harrier-integration.md Shows the dependency injection setup for the MiniLM model. ```csharp using ElBruno.LocalEmbeddings.Extensions; services.AddLocalEmbeddings(options => { options.ModelName = "sentence-transformers/all-MiniLM-L6-v2"; }); // Resolved the same way var generator = serviceProvider.GetRequiredService>>(); ``` -------------------------------- ### Installation Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/azure-hybrid-quickstart.md Command to add the ElBruno.LocalEmbeddings.Azure package to a .NET project. ```bash dotnet add package ElBruno.LocalEmbeddings.Azure ``` -------------------------------- ### appsettings.json Example Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/harrier-integration.md Example configuration for HarrierEmbeddings in appsettings.json. ```json { "HarrierEmbeddings": { "ModelVariant": "Quantized", "MaxSequenceLength": 8192, "InstructionPrefix": "Instruct: Retrieve semantically similar text\nQuery: " } } ``` -------------------------------- ### Configuration using appsettings.json Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/azure-hybrid-quickstart.md Example JSON configuration for Azure embeddings settings. ```json { "AzureEmbeddings": { "Endpoint": "https://my-resource.openai.azure.com", "ApiKey": "your-api-key", "DeploymentName": "text-embedding-3-small", "MaxFallbackAttempts": 3, "TimeoutMilliseconds": 30000, "LogFallbackEvents": true } } ``` -------------------------------- ### Token Counting Example Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/harrier-integration.md Demonstrates how to count tokens in a given text using the generator. ```csharp int tokens = generator.CountTokens("Your text here"); Console.WriteLine($"Token count: {tokens}"); // Includes BOS, EOS, and instruction prefix tokens ``` -------------------------------- ### Example 3: With Custom Configuration Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/azure-hybrid-quickstart.md C# code demonstrating how to configure the Azure fallback with custom options like increased attempts and longer timeouts. ```csharp services.AddLocalEmbeddings(); services.AddLocalEmbeddingsWithAzureFallback(options => { options.Endpoint = azureEndpoint; options.ApiKey = azureKey; options.DeploymentName = deploymentName; options.MaxFallbackAttempts = 5; // More attempts options.TimeoutMilliseconds = 60_000; // Longer timeout options.LogFallbackEvents = true; }); ``` -------------------------------- ### Adding LocalEmbeddings with InMemoryVectorStore Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/getting-started.md Example of how to add LocalEmbeddings with an in-memory vector store and integrate with Microsoft.Extensions.VectorData abstractions. ```csharp using ElBruno.LocalEmbeddings.VectorData.Extensions; using Microsoft.Extensions.VectorData; services.AddLocalEmbeddingsWithInMemoryVectorStore( options => options.ModelName = "sentence-transformers/all-MiniLM-L6-v2") .AddVectorStoreCollection("products"); ``` -------------------------------- ### Install NuGet packages Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/README.md Commands to install the core library and optional integration packages. ```bash dotnet add package ElBruno.LocalEmbeddings ``` ```bash dotnet add package ElBruno.LocalEmbeddings.Harrier ``` ```bash dotnet add package ElBruno.LocalEmbeddings.KernelMemory ``` ```bash dotnet add package ElBruno.LocalEmbeddings.VectorData ``` -------------------------------- ### Getting Started Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/contributing.md Clone the repository, navigate to the directory, and build the project. ```bash git clone https://github.com/elbruno/elbruno.localembeddings.git cd elbruno.localembeddings dotnet build ``` -------------------------------- ### Dependency Injection Swap - After (Harrier) Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/harrier-integration.md Shows the dependency injection setup for the Harrier model. ```csharp using ElBruno.LocalEmbeddings.Harrier.Extensions; services.AddHarrierEmbeddings(options => { options.ModelVariant = HarrierModelVariant.Quantized; }); // Resolved the same way — interface is identical var generator = serviceProvider.GetRequiredService>>(); ``` -------------------------------- ### Accuracy Check Example Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/QUANTIZATION_BENCHMARKS_QUICKSTART.md C# code snippet demonstrating how to check the accuracy metric (cosine similarity) after quantization. ```csharp var similarity = benchmarks.GetAccuracyMetric(); // Returns: 0.9876 (1.0 = identical, >0.95 = acceptable) ``` -------------------------------- ### Quantization Test Examples Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/phase2-implementation-roadmap.md Example unit tests for quantization model loading and fallback behavior. ```csharp [Fact] public void LoadsInt8Model_WhenAvailable() { ... } [Fact] public void FallsBackToFloat32_WhenInt8Missing() { ... } ``` -------------------------------- ### Azure Setup Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/phase2-otel-examples.md Azure CLI commands to create an Application Insights resource and retrieve its connection string. ```bash # Create Application Insights resource az monitor app-insights component create \ --app "embedding-api" \ --location "eastus" \ --resource-group "myResourceGroup" # Get connection string az monitor app-insights component show \ --app "embedding-api" \ --resource-group "myResourceGroup" \ --query connectionString -o tsv ``` -------------------------------- ### Configuring Model Variant for Size Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/harrier-integration.md Example of setting the model variant to a smaller size (Q4) to reduce disk space. ```csharp var options = new HarrierEmbeddingsOptions { ModelVariant = HarrierModelVariant.Q4 // ~196 MB }; ``` -------------------------------- ### Example: With Logging Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/src/ElBruno.LocalEmbeddings.Azure/README.md Example demonstrating how to configure logging for fallback events. ```csharp using Microsoft.Extensions.Logging; var services = new ServiceCollection(); services.AddLogging(builder => { builder.AddConsole(); builder.SetMinimumLevel(LogLevel.Information); }); services.AddLocalEmbeddings(); services.AddLocalEmbeddingsWithAzureFallback(options => { options.Endpoint = "https://my-resource.openai.azure.com"; options.ApiKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY"); options.DeploymentName = "text-embedding-3-small"; options.LogFallbackEvents = true; }); var provider = services.BuildServiceProvider(); var generator = provider.GetRequiredService>>(); // Logs will show: // - When local generation fails // - When falling back to Azure // - Success/failure of each fallback attempt var embeddings = await generator.GenerateAsync(new[] { "test" }); ``` -------------------------------- ### Example 2: With Error Handling Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/azure-hybrid-quickstart.md C# code showing how to handle potential exceptions when generating embeddings, specifically catching InvalidOperationException which might indicate all fallback attempts failed. ```csharp try { var embeddings = await embeddingGenerator.GenerateAsync(["test"]); Console.WriteLine("Embeddings generated successfully"); } catch (InvalidOperationException ex) { Console.WriteLine($"All fallback attempts failed: {ex.Message}"); } ``` -------------------------------- ### Test Sentences Example Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/quantization-benchmarks-methodology.md Example sentences used for quantization benchmarking. ```csharp "The quick brown fox jumps over the lazy dog." "Sample text 0 for quantization benchmarking." "Sample text 1 for quantization benchmarking." ... (up to 100 samples) ``` -------------------------------- ### How to Run Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/src/Samples/ZeroCloudRag/README.md Command to navigate to the sample directory and run the application. ```bash cd samples/ZeroCloudRag dotnet run ``` -------------------------------- ### Registering LocalEmbeddings with IServiceCollection Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/getting-started.md Example of how to register LocalEmbeddings with IServiceCollection for use in production applications, including configuration options and retrieving the embedding generator. ```csharp using ElBruno.LocalEmbeddings.Extensions; using Microsoft.Extensions.AI; using Microsoft.Extensions.DependencyInjection; var services = new ServiceCollection(); services.AddLocalEmbeddings(options => { options.ModelName = "sentence-transformers/all-MiniLM-L6-v2"; options.MaxSequenceLength = 256; }); var provider = services.BuildServiceProvider(); var generator = provider.GetRequiredService>>(); var result = await generator.GenerateAsync(["DI works!"]); Console.WriteLine($"Dimensions: {result[0].Vector.Length}"); ``` -------------------------------- ### Install the package and generate an embedding Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/getting-started.md This snippet shows how to create a new console project, add the ElBruno.LocalEmbeddings package, and generate the first embedding. ```bash dotnet new console -n EmbeddingDemo cd EmbeddingDemo dotnet add package ElBruno.LocalEmbeddings ``` -------------------------------- ### How to Run Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/src/Samples/McpToolRouter/README.md Command to navigate to the sample directory and run the application. ```bash cd samples/McpToolRouter dotnet run ``` -------------------------------- ### Semantic search using FindClosestAsync Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/getting-started.md This example shows how to build a searchable collection of documents and use `FindClosestAsync` to find documents relevant to a query based on meaning. ```csharp using ElBruno.LocalEmbeddings.Extensions; // Build a searchable collection var docs = new[] { "Python for data science", "JavaScript for web apps", "C# for .NET development", "Rust for systems programming", "Swift for iOS development" }; var docEmbeddings = await generator.GenerateAsync(docs); // Search by meaning (one-line helper) var results = await generator.FindClosestAsync( query: "What language for building websites?", corpus: docs, corpusEmbeddings: docEmbeddings, topK: 2, minScore: 0.3f); foreach (var result in results) Console.WriteLine($" {result.Score:P0} — {result.Text}"); // Output: JavaScript for web apps ranks highest ``` -------------------------------- ### Run Benchmarks Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/QUANTIZATION_BENCHMARKS_QUICKSTART.md Navigate to the benchmarks directory and run the benchmarks to generate an HTML report. ```bash # Navigate to benchmarks directory cd src/ElBruno.LocalEmbeddings.Benchmarks # Run benchmarks (generates HTML report) dotnet run --configuration Release --framework net8.0 # View results # → Check BenchmarkDotNet.Artifacts/results/ for HTML report ``` -------------------------------- ### How to Run Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/src/Samples/LocalLlmRag/README.md Command to navigate to the sample directory and run the application. ```bash cd samples/LocalLlmRag dotnet run ``` -------------------------------- ### Build the project from source Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/README.md Commands to clone the repository, navigate to the directory, build the project, and run tests. ```bash git clone https://github.com/elbruno/elbruno.localembeddings.git cd elbruno.localembeddings dotnet build dotnet test ``` -------------------------------- ### GenerateEmbeddings Span Example Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/phase2-opentelemetry-design.md An example of an OpenTelemetry span for the GenerateEmbeddings activity, including its start time, status, attributes, events, and end time. ```text Activity: ElBruno.LocalEmbeddings.GenerateEmbeddings start_time: 2026-05-26T10:15:30.123Z status: OK attributes: llm.system: "local-embeddings" llm.request.model: "sentence-transformers/all-MiniLM-L6-v2" llm.usage.input_tokens: 500 llm.usage.output_dimension: 384 llm.cache_status: "hit" custom.batch_size_actual: 32 events: - name: "embedding_generation_started" timestamp: 2026-05-26T10:15:30.124Z attributes: { batch_size: 32, text_count: 16 } - name: "embedding_batch_completed" timestamp: 2026-05-26T10:15:30.215Z attributes: { batch_number: 1, duration_ms: 91 } end_time: 2026-05-26T10:15:30.230Z duration: 107ms ``` -------------------------------- ### AOT Build Command Example Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/phase2-implementation-roadmap.md Command to publish a .NET 8 application with Native AOT enabled. ```bash dotnet publish -f net8.0 -p:PublishAot=true ``` -------------------------------- ### Docker Compose for Jaeger Setup Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/phase2-otel-examples.md A Docker Compose configuration file to set up Jaeger for distributed tracing, including the Jaeger all-in-one service and an example embedding service that sends traces to Jaeger. ```yaml # docker-compose.yml version: '3.8' services: jaeger: image: jaegertracing/all-in-one:latest ports: - "16686:16686" # Jaeger UI - "14268:14268" # Collector HTTP - "6831:6831/udp" # Agent compact thrift environment: - COLLECTOR_ZIPKIN_HOST_PORT=:9411 - COLLECTOR_OTLP_ENABLED=true command: > --memory.max-traces=10000 --collector.otlp.enabled=true --collector.grpc.host-port=:4317 # Optional: sample application embedding-service: build: . ports: - "5000:5000" environment: - OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4317 depends_on: - jaeger ``` -------------------------------- ### Running ImageRagSimple Sample Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/src/Samples/README_IMAGES.md Command to run the ImageRagSimple console application. ```bash dotnet run --project samples/ImageRagSimple -- ./scripts/clip-models ./samples/images ``` -------------------------------- ### Project Setup Dependencies Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/plans/plan_260216_1445.md List of .NET project dependencies required for the DocumentRagFoundry sample application. ```csharp ElBruno.LocalEmbeddings (text embeddings) ElBruno.LocalEmbeddings.ImageEmbeddings (CLIP image embeddings) PdfSharp (v6.x or latest, for PDF text extraction) PDFium.NET OR SkiaSharp (for PDF page → image conversion) Microsoft.AI.Foundry.Local (Foundry Local lifecycle management) Microsoft.Extensions.AI.OpenAI (OpenAI client adapter) Spectre.Console (interactive UI) ``` -------------------------------- ### Install companion packages for specific integrations Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/blog/blog-rag-3-approaches.md Install companion packages for Microsoft.Extensions.VectorData integration (Sample 1) and Microsoft Kernel Memory integration (Sample 2). ```bash # For Microsoft.Extensions.VectorData integration (Sample 1) dotnet add package ElBruno.LocalEmbeddings.VectorData # For Microsoft Kernel Memory integration (Sample 2) dotnet add package ElBruno.LocalEmbeddings.KernelMemory ``` -------------------------------- ### Batch processing for multiple documents Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/getting-started.md This snippet demonstrates embedding multiple documents in a single call for improved throughput. ```csharp var documents = new[] { "Machine learning is a subset of artificial intelligence.", "JavaScript is widely used for web development.", "C# is developed by Microsoft for .NET applications." }; var embeddings = await generator.GenerateAsync(documents); Console.WriteLine($"Generated {embeddings.Count} embeddings, each with {embeddings[0].Vector.Length} dimensions"); ``` -------------------------------- ### RagFoundryLocal.csproj Example Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/plans/plan_260212_1933_done.md Example .NET project file for the RagFoundryLocal sample, targeting net10.0 and including project references and NuGet packages. ```xml Exe net10.0 enable enable ``` -------------------------------- ### Compare unrelated sentences Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/getting-started.md Demonstrates calculating cosine similarity between unrelated sentences to show a lower similarity score. ```csharp var embeddings = await generator.GenerateAsync(["I love programming", "The weather is nice today"]); float similarity = embeddings[0].CosineSimilarity(embeddings[1]); Console.WriteLine($"Similarity: {similarity:P1}"); // much lower ``` -------------------------------- ### Run Benchmarks Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/QUANTIZATION_BENCHMARKS_SUMMARY.md Command to navigate to the benchmark directory and run the benchmarks using .NET. ```bash cd src/ElBruno.LocalEmbeddings.Benchmarks dotnet run --configuration Release --framework net8.0 ``` -------------------------------- ### Generate an all-pairs similarity matrix Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/getting-started.md This code shows how to generate a similarity matrix for multiple sentences using the `Similarity` extension method. ```csharp using ElBruno.LocalEmbeddings.Extensions; var embeddings = await generator.GenerateAsync(new[] { "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." }); float[,] matrix = embeddings.Similarity(); Console.WriteLine(matrix[0, 1]); // similarity between sentence 0 and 1 ``` -------------------------------- ### Configure Logging Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/azure-hybrid-quickstart.md C# code to configure logging for the application, setting the minimum level to Information and adding a console logger. ```csharp services.AddLogging(builder => { builder.AddConsole(); builder.SetMinimumLevel(LogLevel.Information); }); ``` -------------------------------- ### Generate Markdown Report Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/QUANTIZATION_BENCHMARKS_QUICKSTART.md Command to generate a markdown report from the benchmark results. ```bash dotnet run --configuration Release --framework net8.0 -- \ --format markdown > report.md ``` -------------------------------- ### Compare two sentences using Cosine Similarity Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/getting-started.md This snippet shows how to embed two sentences and calculate their cosine similarity to determine how alike they are. ```csharp using ElBruno.LocalEmbeddings.Extensions; // for CosineSimilarity var embeddings = await generator.GenerateAsync(["I love programming", "I enjoy coding"]); float similarity = embeddings[0].CosineSimilarity(embeddings[1]); Console.WriteLine($"Similarity: {similarity:P1}"); // ~85%+ ``` -------------------------------- ### Generate your first embedding Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/getting-started.md This C# code demonstrates how to create an embedding generator, generate an embedding for a single string, and print its dimensions and initial values. ```csharp using ElBruno.LocalEmbeddings; // Create the generator (downloads model automatically on first run) // Async factory is recommended in ASP.NET/UI contexts. await using var generator = await LocalEmbeddingGenerator.CreateAsync(); // Generate an embedding — single-string convenience method var embedding = await generator.GenerateEmbeddingAsync("Hello, world!"); float[] vector = embedding.Vector.ToArray(); Console.WriteLine($"Dimensions: {vector.Length}"); // 384 Console.WriteLine($"First 3 values: {vector[0]:F4}, {vector[1]:F4}, {vector[2]:F4}"); ``` -------------------------------- ### Quick Run (Development) Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/quantization-benchmarks-methodology.md Command to run a quick version of the quantization benchmarks for development purposes. ```bash cd src/ElBruno.LocalEmbeddings.Benchmarks dotnet run --configuration Release -- --filter "*QuantizedVsFullBenchmarks*" ``` -------------------------------- ### Docker Compose: Datadog Agent Setup Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/phase2-otel-examples.md Docker Compose configuration to set up the Datadog Agent for APM, logs, and metrics, and configure the embedding service to send data to it. ```yaml # docker-compose.yml version: '3.8' services: datadog-agent: image: datadog/agent:latest ports: - "8126:8126" # APM Agent - "8125:8125/udp" # StatsD environment: - DD_API_KEY=${DATADOG_API_KEY} - DD_SITE=datadoghq.com - DD_APM_ENABLED=true - DD_LOGS_ENABLED=true - DD_METRICS_ENABLED=true volumes: - /var/run/docker.sock:/var/run/docker.sock:ro embedding-service: build: . ports: - "5000:5000" environment: - OTEL_EXPORTER_OTLP_ENDPOINT=http://datadog-agent:4317 - DD_TRACE_AGENT_PORT=8126 depends_on: - datadog-agent ``` -------------------------------- ### RagOllama.csproj Example Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/plans/plan_260212_1933_done.md Example .NET project file for the RagOllama sample, targeting net10.0 and including project references and NuGet packages. ```xml Exe net10.0 enable enable ``` -------------------------------- ### Example Trace in Jaeger Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/phase2-otel-trace-design.md A textual representation of a span's details as it might appear in Jaeger, including start time, tags, end time, and duration. ```text Span: GenerateEmbeddings (elapsed: 87ms) ├─ start_time: 2026-05-26T10:15:30.123Z ├─ tags: │ ├─ llm.system: "local-embeddings" │ ├─ llm.request.model: "sentence-transformers/all-MiniLM-L6-v2" │ ├─ llm.usage.input_tokens: 500 │ ├─ llm.usage.output_dimension: 384 │ ├─ llm.quantization_format: "int8" │ ├─ custom.input_count: 16 │ ├─ custom.batch_count: 1 │ ├─ custom.batch_size_actual: 16 │ ├─ custom.cache_status: "hit" │ ├─ custom.inference_time_ms: 8.2 │ └─ otel.status_code: "OK" ├─ end_time: 2026-05-26T10:15:30.230Z └─ duration: 87ms ``` -------------------------------- ### Reduce Iterations Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/QUANTIZATION_BENCHMARKS_QUICKSTART.md Command to reduce the number of iterations for faster, less accurate benchmark runs. ```bash dotnet run --configuration Release --framework net8.0 -- \ -i 5 # Only 5 iterations instead of ~100 ``` -------------------------------- ### Agent Wiring - Core Code Setup Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/blog/blog-vision-memory-agent-ollama.md C# code demonstrating the setup of the local agent with function tools using OllamaChatClient and Agent Framework. ```csharp IChatClient chatClient = new OllamaChatClient(new Uri("http://localhost:11434"), modelId: ollamaModel) .AsBuilder() .UseFunctionInvocation() .Build(); var tools = new[] { AIFunctionFactory.Create(IngestImage), AIFunctionFactory.Create(FindSimilarImages), AIFunctionFactory.Create(IngestImagesFromFolder) }; AIAgent agent = chatClient.AsAIAgent( name: "VisionMemoryAgent", instructions: """ You are a Vision Memory agent. You help users manage and search a local image collection. You have three tools: - IngestImage: to add an image to the in-memory store - IngestImagesFromFolder: to add all images from a folder to the in-memory store - FindSimilarImages: to search stored images using natural language Always use the tools when the user asks to ingest or search images. Report tool results clearly. """, tools: [.. tools]); AgentSession session = await agent.CreateSessionAsync(); ``` -------------------------------- ### RAG Key Code Pattern Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/getting-started.md Illustrates the core logic for Retrieval-Augmented Generation (RAG), including embedding a question, searching for similar documents, building a prompt, and streaming the LLM response. ```csharp // 1. Embed the user's question (single-string convenience method) var queryEmbedding = await embeddingGenerator.GenerateEmbeddingAsync(userQuestion); // 2. Find the most relevant documents var results = vectorStore.Search(queryEmbedding, topK: 3); // 3. Build a prompt with retrieved context var context = string.Join("\n\n", results.Select(r => r.Content)); var prompt = $""" Answer the question using only the context below. Context: {context} Question: {userQuestion} """; // 4. Stream the LLM response await foreach (var chunk in chatClient.GetStreamingResponseAsync(prompt)) Console.Write(chunk); ``` -------------------------------- ### Run the sample Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/blog/blog-vision-memory-agent-ollama.md Command to run the Vision Memory Agent sample from the repository root. ```bash # From repo root dotnet run --project src/src/Samples/VisionMemoryAgentSample -- --model-dir ./scripts/clip-models ``` -------------------------------- ### Install NuGet Package Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/src/ElBruno.LocalEmbeddings.OpenTelemetry/README.md Installs the ElBruno.LocalEmbeddings.OpenTelemetry NuGet package. ```bash dotnet add package ElBruno.LocalEmbeddings.OpenTelemetry ``` -------------------------------- ### Run Specific Benchmark Source: https://github.com/elbruno/elbruno.localembeddings/blob/main/docs/QUANTIZATION_BENCHMARKS_QUICKSTART.md Command to run a specific benchmark using a filter. ```bash dotnet run --configuration Release --framework net8.0 -- \ --filter "*Batch32*" ```