You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Documentation/7.1/Raven.Documentation.Pages/ai-integration/gen-ai-integration/gen-ai-api.markdown
+32-44Lines changed: 32 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,50 +3,41 @@
3
3
4
4
{NOTE: }
5
5
6
-
* A GenAI task leverage an AI model to enable intelligent processing of documents in runtime.
7
-
* The task is associated with a documents collection and with an AI model.
8
-
* It is an ongoing task that continuously monitors the collection and whenever needed
9
-
(e.g. when a document is added to it) retrieves document data, structures it, sends
10
-
the structured data object ("context object") to the AI model for processing, receives
11
-
the model's replies and acts upon them as needed.
12
-
13
-
* The main steps in the definition of a GenAI task are:
14
-
* Defining a **connection string** that the task can connect the AI model with.
15
-
* Defining a **context objects creation** JavaScript.
16
-
To process a document, the task first runs a JavaScript on it to create **context objects**.
17
-
These objects are then sent one by one to the AI model for processing.
18
-
Each context object is sent to the model along with the Prompt and JSON schema
19
-
defined for this task, instructing the model what to do with the data and how
20
-
to structure its reply.
21
-
* Defining a **Prompt**.
22
-
The prompt, written in regular English, instructs the AI model what to do with the data passed to it.
23
-
* Defining a **JSON schema** Javascript.
24
-
The schema script instructs the AI model how to structure its replies.
25
-
* Defining an **Update JavaScript**.
26
-
The update script is executed over replies returned from the AI model.
27
-
It can, for example, modify or delete documents based on the conclusions made by the AI model.
6
+
* A GenAI task leverages an AI model to enable intelligent processing of documents in runtime.
7
+
* The task is associated with a document collection and with an AI model.
8
+
* It is an **ongoing task** that:
9
+
1. Continuously monitors the collection;
10
+
2. Whenever needed, like when a document is added to the collection, generates
11
+
user-defined context objects based on the source document data;
12
+
3. Passes each context object to the AI model for further processing;
13
+
4. Receives the AI model's JSON-based results;
14
+
5. And finally, runs a user-defined script that potentially acts upon the results.
15
+
16
+
* The main steps in defining a GenAI task are:
17
+
* Defining a [Connection string](../../ai-integration/gen-ai-integration/gen-ai-api#defining-a-connection-string)
18
+
to the AI model
19
+
* Defining a [Context generation script](../../ai-integration/gen-ai-integration/gen-ai-overview#the-elements_context-objects)
20
+
* Defining a [Prompt](../../ai-integration/gen-ai-integration/gen-ai-overview#the-elements_prompt)
21
+
* Defining a [JSON schema](../../ai-integration/gen-ai-integration/gen-ai-overview#the-elements_json-schema)
22
+
* Defining an [Update script](../../ai-integration/gen-ai-integration/gen-ai-overview#the-elements_update-script)
28
23
29
24
* In this article:
30
25
*[Defining a Connection string](../../ai-integration/gen-ai-integration/gen-ai-api#defining-a-connection-string)
31
26
*[Defining the GenAI task](../../ai-integration/gen-ai-integration/gen-ai-api#defining-the-genai-task)
32
-
27
+
33
28
{NOTE/}
34
29
35
30
---
36
31
37
32
{PANEL: Defining a Connection string}
38
33
39
-
The GenAI task can connect and leverage a variety of AI models, each requiring
40
-
its own connection string.
41
-
42
-
* Learn how to define a connection string for various AI destinations in the
43
-
[article dedicated to this subject](../../ai-integration/connection-strings/connection-strings-overview).
44
-
* Choose what model to connect by your requirements from your GenAI task.
45
-
If you require security and speed above all, for example, for the duration of a development
46
-
phase you're in, you may prefer a local AI model like [Ollama](../../ai-integration/connection-strings/ollama).
47
-
***Note** that each AI model may apply different engines for different purposes.
48
-
We need to handle and generate text, so if we use Ollama, for example, we can
49
-
apply its `llama3.2` model, or if we use OpenAI we can apply `gpt-4o-mini`.
34
+
* Choose the model to connect with, by what you need from your GenAI task.
35
+
E.g., If you require security and speed above all for the duration of a rapid
36
+
development phase, you may prefer a local AI service like [Ollama](../../ai-integration/connection-strings/ollama).
37
+
* Make sure you define the correct service: both Ollama and OpenAI are supported
38
+
but you need to pick an Ollama/OpenAI service that supports generative AI,
39
+
like Ollama `llama3.2` or OpenAI `gpt-4o-mini`.
40
+
* Learn more about connection strings [here](../../ai-integration/connection-strings/connection-strings-overview).
50
41
51
42
---
52
43
@@ -85,28 +76,25 @@ its own connection string.
85
76
|**Identifier**|`string`| Unique task identifier, embedded in documents metadata to indicate they were processed along with hash codes for their processed parts |
86
77
|**ConnectionStringName**|`string`| Connection string name |
87
78
|**Disabled**|`bool`| Determines whether the task is enabled or disabled |
88
-
|**Collection**|`string`| Name of the documents collection associated with the task |
89
-
|**GenAiTransformation**|`GenAiTransformation`| Context generation script - format for objects to be sentto the AI model |
79
+
|**Collection**|`string`| Name of the document collection associated with the task |
80
+
|**GenAiTransformation**|`GenAiTransformation`| Context generation script - format for objects to be sent to the AI model |
90
81
|**Prompt**|`string`| AI model Prompt - the instructions sent to the AI model |
91
82
|**SampleObject**|`string`| JSON schema - a sample response object to format AI model replies by |
92
83
|**UpdateScript**|`string`| Update script - specifies what to do with AI model replies |
93
-
|**MaxConcurrency**|`int`| Max concurrent connections to AI model (remember that each context object is sent using its own separate connection|
84
+
|**MaxConcurrency**|`int`| Max concurrent connections to the AI model (each connection serving a single context object|
RavenDB offers an integration of generative AI capabilities through userdefined **GenAI tasks**.
37
-
A GenAI task is an ongoing process that continuously monitors a document collection associated with
38
-
it, and reacts when a document is added or modified by Retrieving the document, Structuring it into
39
-
"context objects", Sending these objects to a generative AI model along with instructions regarding
40
-
what to do with the data and how to shape the reply, and potentially Acting upon the model's response.
37
+
RavenDB offers an integration of generative AI capabilities through user-defined **GenAI tasks**.
38
+
A GenAI task is an ongoing process that continuously monitors a document collection associated with it,
39
+
and reacts when a document is added or modified by Retrieving the document, Generating "context objects"
40
+
based on its data, Sending these objects to a generative AI model along with instructions regarding what
41
+
to do with the data and how to format the reply, and potentially Acting upon the model's response.
41
42
42
43
{CONTENT-FRAME: <aid="the-flow" />The flow}
43
44
Let's put the above stages in order.
@@ -46,28 +47,119 @@ Let's put the above stages in order.
46
47
47
48
1. The task continuously monitors the collection it is associated with.
48
49
2. When a document is added or modified, the task retrieves it.
49
-
3. The task structure the data contained in the document into **Context objects**.
50
-
The structuring is done by a "context creation script" (JavaScript) you provide,
51
-
that uses our `ai.genContext` method for the creation of each context object.
50
+
3. The task generates context objects based on the source document data.
51
+
To generate these objects, the task applies a user-defined [context generation script](../../ai-integration/gen-ai-integration/gen-ai-overview#the-elements_context-objects)
52
+
that runs through the source document and generates context objects based on the document data.
52
53
4. The task sends each context object to a GenAI model for processing.
53
-
* The task is associated with a **Connection string** that defines how to connect to the AI model.
54
-
* Each context object is sent over its own separate connection to the AI model.
55
-
* Each object is sent along with a **Prompt** and a **JSON schema**.
56
-
The prompt is written in regular english, with your instructions to the AI model.
57
-
The schema defines how the model is to structure its replies.
58
-
5. The task can then apply an **Update script** (JavaScript) to handle the results.
54
+
* The task is associated with a [Connection string](../../ai-integration/gen-ai-integration/gen-ai-studio#studio_connection-string)
55
+
that defines how to connect to the AI model.
56
+
* Each context object is sent via a separate connection to the AI model.
57
+
- The number of concurrent connections to the AI model is configurable
58
+
via the [MaxConcurrency](../../ai-integration/gen-ai-integration/gen-ai-api#section) variable.
59
+
* Each context object is sent along with a user-defined [Prompt](../../ai-integration/gen-ai-integration/gen-ai-overview#the-elements_prompt),
60
+
that instructs the AI model what to do with the data, and
61
+
a user-defined [JSON schema](../../ai-integration/gen-ai-integration/gen-ai-overview#the-elements_json-schema)
62
+
that instructs the AI model how to shape its response.
63
+
5. When the AI model returns its response, a user-defined [Update script](../../ai-integration/gen-ai-integration/gen-ai-overview#the-elements_update-script)
0 commit comments