Skip to content

7.1.4 πŸŽ‰

Latest

Choose a tag to compare

@poissoncorp poissoncorp released this 10 Dec 16:27
7e83006

7.1.4 continues the AI integration story: it adds GenAI Tasks (document-level AI processing), introduces structured prompts with ContentPart, and brings enhanced agent parameters with visibility control. This release syncs the Python client with RavenDB 7.1.4.

If you're new to AI in RavenDB, start here:

PyPi link: https://pypi.org/project/ravendb/7.1.4/


Highlights

GenAI Tasks

New GenAI Tasks let you automatically process documents with AI. Define a prompt, point it at a collection, and RavenDB handles the rest - calling the model, updating documents, and tracking progress.

from ravendb.documents.operations.ai import (
    GenAiConfiguration,
    GenAiTransformation,
    AddGenAiOperation,
)
from ravendb.documents.starting_point_change_vector import StartingPointChangeVector

# Configure the GenAI task
config = GenAiConfiguration(
    name="DocumentSummarizer",
    identifier="doc-summarizer",
    collection="Articles",
    connection_string_name="openai-connection",
    prompt="Summarize the following article",
    gen_ai_transformation=GenAiTransformation(script="ai.genContext({text: this.Content});"),
    update_script="this.Summary = $output.Summary;",
    sample_object='{"Summary": "A brief summary of the article"}',
    max_concurrency=4,
)

# Add the task and start processing documents
result = store.maintenance.send(AddGenAiOperation(config))
print(f"Task created with ID: {result.task_id}")

# Start from the beginning
result = store.maintenance.send(
    AddGenAiOperation(config, StartingPointChangeVector.BEGINNING_OF_TIME)
)

Full CRUD operations are available:

from ravendb.documents.operations.ongoing_tasks import (
    GetOngoingTaskInfoOperation,
    DeleteOngoingTaskOperation,
    OngoingTaskType,
)
from ravendb.documents.operations.ai import UpdateGenAiOperation

# Get task info
task = store.maintenance.send(
    GetOngoingTaskInfoOperation(result.task_id, OngoingTaskType.GEN_AI)
)

# Update task (with optional reset to reprocess documents)
config.prompt = "Updated prompt: Provide a detailed summary"
config.task_id = result.task_id
store.maintenance.send(UpdateGenAiOperation(result.task_id, config, reset=True))

# Delete task
store.maintenance.send(
    DeleteOngoingTaskOperation(result.task_id, OngoingTaskType.GEN_AI)
)

Structured Prompts with ContentPart

Prompts now support structured content parts for richer interactions:

from ravendb.documents.ai import TextPart, ContentPart
 
chat.add_user_prompt("Analyze this document")  # New method
chat.set_user_prompt("Analyze this document")  # Still works as before

# The prompt is internally converted to:
# [TextPart("Analyze this document")]

Enhanced Agent Parameters

Agent parameters now support descriptions and visibility control:

from ravendb.documents.operations.ai.agents import AiAgentConfiguration, AiAgentParameter

config = AiAgentConfiguration(
    identifier="my-agent",
    name="Customer Support Agent",
    system_prompt="You are helping {{user}}. Their account type is {{account_type}}.",
    parameters=[
        # Simple string (backward compatible)
        "user",
        # Full parameter with description and visibility
        AiAgentParameter(
            name="account_type",
            description="The customer's subscription tier",
            send_to_model=False, 
        ),
    ],
)

When send_to_model=False, the parameter value is substituted into the prompt but not exposed in echo messages or other model interactions, which is useful for sensitive data.


Reasoning Tokens & Usage Tracking

AiUsage now tracks reasoning tokens (for models that use chain-of-thought):

result = chat.run("response")
print(f"Reasoning tokens: {result.usage.reasoning_tokens}")
print(f"Total tokens: {result.usage.total_tokens}")

# Calculate usage difference between turns
diff = AiUsage.get_usage_difference(current_usage, previous_usage)

PR

(yeah, singular)

Full Changelog: 7.1.3...7.1.4