Skip to content

GenAI documentation - fix by review comments #2061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@
* Define a GenAI task using a `GenAiConfiguration` object.
* Run the task using `AddGenAiOperation`.

{CODE:csharp gen-ai_define-gen-ai-task@AiIntegration\GenAI\GenAI.cs /}
{CODE-TABS}
{CODE-TAB:csharp:use-sample-object gen-ai_define-gen-ai-task_use-sample-object@AiIntegration\GenAI\GenAI.cs /}
{CODE-TAB:csharp:use-json-schema gen-ai_define-gen-ai-task_use-json-schema@AiIntegration\GenAI\GenAI.cs /}
{CODE-TABS/}

---

Expand All @@ -79,7 +82,8 @@
| **Collection** | `string` | Name of the document collection associated with the task |
| **GenAiTransformation** | `GenAiTransformation` | Context generation script - format for objects to be sent to the AI model |
| **Prompt** | `string` | AI model Prompt - the instructions sent to the AI model |
| **SampleObject** | `string` | JSON schema - a sample response object to format AI model replies by |
| **SampleObject** | `string` | A [sample response object](../../ai-integration/gen-ai-integration/gen-ai-overview#the-elements_json-schema) to format the AI model's replies by <br> If both a `SampleObject` and a `JsonSchema` are provided the schema takes precedence |
| **JsonSchema** | `string` | A [JSON schema](../../ai-integration/gen-ai-integration/gen-ai-overview#the-elements_json-schema) to format the AI model's replies by <br> If both a `SampleObject` and a `JsonSchema` are provided the schema takes precedence |
| **UpdateScript** | `string` | Update script - specifies what to do with AI model replies |
| **MaxConcurrency** | `int` | Max concurrent connections to the AI model (each connection serving a single context object |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Raven.Client.Documents.Operations.ConnectionStrings;
using Raven.Client.Documents.Operations.ETL;
using Sparrow.Json;
using static Akka.Streams.Attributes;
using static Akka.Streams.Implementation.Fusing.GraphInterpreter;

namespace Raven.Documentation.Samples.AiIntegration.ConnectionStrings;
Expand Down Expand Up @@ -65,7 +66,7 @@ public async Task Examples()

using (var store = new DocumentStore())
{
#region gen-ai_define-gen-ai-task
#region gen-ai_define-gen-ai-task_use-sample-object
GenAiConfiguration config = new GenAiConfiguration
{
// Task name
Expand Down Expand Up @@ -94,7 +95,7 @@ public async Task Examples()
// AI model Prompt - the instructions sent to the AI model
Prompt = "Check if the following blog post comment is spam or not",

// JSON schema - a sample response object to format AI model replies by
// Sample object - a sample response object to format the AI model's replies by
SampleObject = JsonConvert.SerializeObject(
new
{
Expand Down Expand Up @@ -122,6 +123,81 @@ public async Task Examples()
var addAiIntegrationTaskResult = store.Maintenance.Send(GenAiOperation);
#endregion
}

using (var store = new DocumentStore())
{
#region gen-ai_define-gen-ai-task_use-json-schema
GenAiConfiguration config = new GenAiConfiguration
{
// Task name
Name = "FilterSpam",

// Unique task identifier
Identifier = "FilterSpam",

// Connection string to AI model
ConnectionStringName = "ollama-cs",

// Task is enabled
Disabled = false,

// Collection associated with the task
Collection = "Posts",

// Context generation script - format for objects to be sentto the AI model
GenAiTransformation = new GenAiTransformation {
Script = @"
for(const comment of this.Comments)
{
ai.genContext({Text: comment.Text, Author: comment.Author, Id: comment.Id});}"
},

// AI model Prompt - the instructions sent to the AI model
Prompt = "Check if the following blog post comment is spam or not",

// JSON schema - a schema to format the AI model's replies by
JsonSchema = @"{
""name"": """ + "some-name" + @""",
""strict"": true,
""schema"": {
""type"": ""object"",
""properties"": {
""Blocked"": {
""type"": ""boolean""
},
""Reason"": {
""type"": ""string"",
""description"": ""Concise reason for why this comment was marked as spam or ham""
}
},
""required"": [
""Blocked"",
""Reason""
],
""additionalProperties"": false
}
}",

// Update script - specifies what to do with AI model replies
UpdateScript = @"
// Find the comment
const idx = this.Comments.findIndex(c => c.Id == $input.Id);
// Was detected as spam
if($output.Blocked)
{
// Remove this comment
this.Comments.splice(idx, 1);
}",

// Max concurrent connections to AI model
MaxConcurrency = 4
};

// Run the task
var GenAiOperation = new AddGenAiOperation(config);
var addAiIntegrationTaskResult = store.Maintenance.Send(GenAiOperation);
#endregion
}

}
}
Expand Down
Loading