-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRagExample.cs
More file actions
97 lines (79 loc) · 3.8 KB
/
Copy pathRagExample.cs
File metadata and controls
97 lines (79 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using Delibera.Core.Council;
using Delibera.Core.Models;
using Delibera.Core.Providers;
using Delibera.Core.Providers.LLM;
using Delibera.Core.Providers.RAG;
namespace Delibera.ConsoleApp.Examples;
/// <summary>
/// RAG example — demonstrates Qdrant integration, document indexing,
/// Knowledge Keeper and a debate enriched with vector-search context.
/// </summary>
public static class RagExample
{
public static async Task RunAsync()
{
// ── 1. LLM provider ──
using var factory = new ProviderFactory();
var ollama = factory.CreateOllama("http://localhost:11434");
// ── 2. Embedding provider (uses Ollama) ──
var embeddings = new OllamaEmbeddingProvider(ollama, "nomic-embed-text");
// ── 3. RAG provider (Qdrant) ──
await using var ragFactory = new RagProviderFactory();
var rag = ragFactory.CreateQdrant(embeddings);
// ── 4. Knowledge Keeper ──
var kkModel = new CouncilMember("llama2", ollama, "Knowledge Keeper");
var keeper = new KnowledgeKeeper(rag, kkModel, "architecture_kb");
// ── 5. Index documents ──
Console.WriteLine("📚 Indexing documents...");
var docText = """
# Microservices Best Practices
## Service Design
- Each microservice should own its data
- Services communicate via APIs (REST, gRPC, or message queues)
- Keep services small and focused (single responsibility)
## Deployment
- Use containers (Docker) for consistent environments
- Kubernetes for orchestration at scale
- CI/CD pipelines per service
## Monitoring
- Distributed tracing (Jaeger, Zipkin)
- Centralised logging (ELK stack)
- Health checks and circuit breakers
## When NOT to use microservices
- Small teams (< 5 developers)
- Early-stage startups exploring product-market fit
- Simple CRUD applications
- When the domain is not well understood
""";
var chunks = await keeper.IndexDocumentAsync(docText, new Dictionary<string, string> { ["topic"] = "microservices" });
Console.WriteLine($" ✅ Indexed {chunks} chunks");
// ── 6. Build council with Knowledge Keeper ──
var executor = new CouncilBuilder()
.AddMember("llama2", ollama, "Backend Expert")
.AddMember("qwen2.5", ollama, "DevOps Expert")
.SetChairman(Chairman.CreateStandard("qwen2.5", ollama))
.WithKnowledgeKeeper(keeper)
.WithStandardDebate()
.WithSystemPrompt("You are a senior software architect.")
.WithUserPrompt("Our startup has 4 developers. Should we adopt microservices now or start with a monolith?")
.WithMaxRounds(4)
.SaveResultTo("./results/rag_debate.md")
.Build();
Console.WriteLine(executor.GetInfo());
// ── 7. Run debate ──
executor.OnRoundCompleted += round =>
{
Console.WriteLine($"✅ Round {round.RoundNumber}: {round.RoundName}");
if (round.KnowledgeInteractions.Count > 0)
Console.WriteLine($" 📚 {round.KnowledgeInteractions.Count} Knowledge Keeper query(s)");
};
var result = await executor.ExecuteAsync();
Console.WriteLine($"\n🏆 Debate completed in {result.TotalDuration.TotalSeconds:F1}s");
Console.WriteLine("📁 Saved to: ./results/rag_debate.md");
if (!string.IsNullOrWhiteSpace(result.FinalVerdict))
{
Console.WriteLine("\n══ FINAL VERDICT ══\n");
Console.WriteLine(result.FinalVerdict);
}
}
}