Table of contents
Official Content
  • This documentation is valid for:

The RAG Assistants API via Python SDK - PyGEAI enables you to interact with the RAG Assistants in Globant Enterprise AI, so you can index and retrieve documents and execute queries with configurable search and indexing options.

You can perform the following actions:

  • Create a RAG Assistant: Creates a new RAG Assistant with search, indexing, and welcome data options.
  • Update a RAG Assistant: Updates an existing RAG Assistant’s status and configuration.
  • Delete a RAG Assistant: Deletes an existing RAG Assistant by name.
  • List RAG Assistants: Retrieves all RAG Assistants in a Project.
  • Get a RAG Assistant: Retrieves details of a specific RAG Assistant by name.
  • Upload document: Uploads a document for indexing and retrieval.
  • Retrieve document: Retrieves a specific document by its ID.
  • List documents: Lists documents associated with a RAG Assistant.
  • Delete document: Deletes a specific document by its ID.
  • Delete all documents: Deletes all documents associated with a RAG Assistant.
  • Execute query: Executes a query against the assistant’s indexed documents.

To run them, choose one of the following options:

  1. Command Line
  2. Low-Level Service Layer
  3. High-Level Service Layer

Create RAG Assistant

Creates a new RAG Assistant with configurable options for search, indexing, and welcome data. A name is required, while description, template, search options, index options, and welcome data are optional.

1. Command Line

You can create a RAG Assistant using the following Command Line options:

geai rag create-assistant 
  -n "MyRAGAssistant" 
  -d "RAG Assistant for document retrieval" 
  --template "default_rag_template" 
  --history-count 5 
  --model-name "gpt-4" 
  --temperature 0.7 
  --chunk-size 512 
  --chunk-overlap 50 
  --wd-title "Welcome to My Assistant" 
  --wd-description "This assistant helps retrieve and summarize documents."

Where:

  • -n, --name: (Required) Name of the RAG Assistant.
  • -d, --description: Description of the assistant's purpose.
  • --template, --tpl: Name of an existing RAG template (optional).
  • --history-count, --hc: Number of historical interactions to include.
  • --model-name, -m: LLM model name (e.g., "gpt-4").
  • --temperature, --temp, -t: Sampling temperature for LLM responses.
  • --chunk-size: Size of each document chunk.
  • --chunk-overlap: Overlap size between chunks.
  • --wd-title: Title for welcome data.
  • --wd-description: Description for welcome data.

Additional parameters for search, index, and welcome data are available; refer to geai rag create-assistant -h.

2. Low-Level Service Layer

Use the following code snippet to create a RAG Assistant using the Low-Level Service Layer:

from pygeai.assistant.rag.clients import RAGAssistantClient

name = "MyRAGAssistant"
description = "RAG Assistant for document retrieval"
template = "default_rag_template"
search_options = {
    "history_count": 5,
    "llm": {
        "modelName": "gpt-4",
        "temperature": 0.7,
        "maxTokens": 1000
    },
    "search": {
        "k": 10,
        "type": "similarity"
    }
}
index_options = {
    "chunks": {
        "chunk_size": 512,
        "chunkOverlap": 50
    }
}
welcome_data = {
    "title": "Welcome to My Assistant",
    "description": "This assistant helps retrieve and summarize documents."
}

client = RAGAssistantClient()
new_assistant = client.create_assistant(
    name=name,
    description=description,
    template=template,
    search_options=search_options,
    index_options=index_options,
    welcome_data=welcome_data
)
print(new_assistant)

Where:

  • name: (Required) Name of the RAG Assistant.
  • description: Optional description of the assistant's purpose.
  • template: Optional name of an existing RAG template.
  • search_options: Dictionary configuring search behavior (e.g., LLM settings, search type).
  • index_options: Dictionary configuring document indexing (e.g., chunk size, overlap).
  • welcome_data: Dictionary configuring the welcome message.

Returns: A dictionary containing the API response with details of the created assistant.

3. High-Level Service Layer

Use the following code snippet to create a RAG Assistant using the High-Level Service Layer:

from pygeai.assistant.managers import AssistantManager
from pygeai.assistant.rag.models import RAGAssistant, SearchOptions, IndexOptions, WelcomeData

manager = AssistantManager()

search_options = SearchOptions(
    history_count=5,
    llm={
        "modelName": "gpt-4",
        "temperature": 0.7,
        "maxTokens": 1000
    },
    search={
        "k": 10,
        "type": "similarity"
    }
)
index_options = IndexOptions(
    chunks={
        "chunk_size": 512,
        "chunkOverlap": 50
    }
)
welcome_data = WelcomeData(
    title="Welcome to My Assistant",
    description="This assistant helps retrieve and summarize documents."
)

assistant = RAGAssistant(
    name="MyRAGAssistant",
    description="RAG Assistant for document retrieval",
    template="default_rag_template",
    search_options=search_options,
    index_options=index_options,
    welcome_data=welcome_data
)

created_assistant = manager.create_assistant(assistant)
print(created_assistant)

Returns: A created RAG Assistant instance or an error response.

Update RAG Assistant

Updates an existing RAG Assistant’s status, description, template, search options, or welcome data. The Assistant name and status are required.

1. Command Line

You can update a RAG Assistant using the following Command Line options:

geai rag update-assistant 
  -n "MyRAGAssistant" 
  --status 1 
  -d "Updated RAG Assistant description"

Where:

  • -n, --name: (Required) Name of the RAG Assistant.
  • --status: (Required) Status (1 for enabled, 0 for disabled).
  • -d, --description: Updated description.
  • --template, --tpl: Updated template name.

Additional parameters for search options and welcome data are available; refer to geai rag update-assistant -h.

2. Low-Level Service Layer

Use the following code snippet to update a RAG Assistant using the Low-Level Service Layer:

client = RAGAssistantClient()
updated_assistant = client.update_assistant(
    name="MyRAGAssistant",
    status=1,
    description="Updated RAG Assistant description",
    search_options={
        "history_count": 10,
        "llm": {"modelName": "gpt-4", "temperature": 0.8}
    }
)
print(updated_assistant)

Where:

  • name: (Required) Name of the RAG Assistant.
  • status: (Required) Status (1 for enabled, 0 for disabled).
  • description: Optional updated description.
  • template: Optional updated template name.
  • search_options: Optional updated search configuration.
  • welcome_data: Optional updated welcome message configuration.

Returns: A dictionary containing the API response with details of the updated assistant.

3. High-Level Service Layer

Use the following code snippet to update a RAG Assistant using the High-Level Service Layer:

from pygeai.assistant.managers import AssistantManager
from pygeai.assistant.rag.models import RAGAssistant, SearchOptions

manager = AssistantManager()
assistant = RAGAssistant(
    name="MyRAGAssistant",
    status=1,
    description="Updated RAG Assistant description",
    search_options=SearchOptions(
        history_count=10,
        llm={"modelName": "gpt-4", "temperature": 0.8}
    )
)
updated_assistant = manager.update_assistant(assistant)
print(updated_assistant)

Returns: A RAGAssistant instance with updated details, or an error response.

Delete RAG Assistant

Deletes an existing RAG Assistant by name.

1. Command Line

You can delete a RAG Assistant using the following Command Line options:

geai rag delete-assistant -n "MyRAGAssistant"

Where:

  • -n, --name: (Required) Name of the RAG Assistant.

2. Low-Level Service Layer

Use the following code snippet to delete a RAG Assistant using the Low-Level Service Layer:

client = RAGAssistantClient()
result = client.delete_assistant(name="MyRAGAssistant")
print(result)

Where:

  • name: (Required) Name of the RAG Assistant.

Returns: A dictionary indicating deletion success or failure.

3. High-Level Service Layer

Use the following code snippet to delete a RAG Assistant using the High-Level Service Layer:

from pygeai.assistant.managers import AssistantManager

manager = AssistantManager()
result = manager.delete_assistant(assistant_name="MyRAGAssistant")
print(result)

Returns: An EmptyResponse indicating success, or an error response.

List RAG Assistants

Retrieves all RAG Assistants in a Project.

1. Command Line

You can list RAG Assistants using the following Command Line options:

geai rag list-assistants

2. Low-Level Service Layer

Use the following code snippet to list RAG Assistants using the Low-Level Service Layer:

client = RAGAssistantClient()
assistants = client.get_assistants_from_project()
print(assistants)

Returns: A dictionary containing a list of RAG Assistants in the project.

3. High-Level Service Layer

Use the High-Level Service Layer to retrieve a specific RAG Assistant by name:

from pygeai.assistant.managers import AssistantManager

manager = AssistantManager()
assistant = manager.get_assistant_data(assistant_name="MyRAGAssistant")
print(assistant)

Note: The high-level manager retrieves a specific assistant by name. To list all assistants, use the low-level client or CLI.

Returns: A RAGAssistant instance for the specified assistant, or an error response.

Get RAG Assistant

Retrieves details of a specific RAG Assistant by name.

1. Command Line

You can retrieve a RAG Assistant using the following Command Line options:

geai rag get-assistant -n "MyRAGAssistant"

Where:

  • -n, --name: (Required) Name of the RAG Assistant.

2. Low-Level Service Layer

Use the following code snippet to retrieve a RAG Assistant using the Low-Level Service Layer:

client = RAGAssistantClient()
assistant_data = client.get_assistant_data(name="MyRAGAssistant")
print(assistant_data)

Where:

  • name: (Required) Name of the RAG Assistant.

Returns: A dictionary containing the Assistant’s details.

3. High-Level Service Layer

Use the following code snippet to retrieve a RAG Assistant using the High-Level Service Layer:

from pygeai.assistant.managers import AssistantManager

manager = AssistantManager()
assistant = manager.get_assistant_data(assistant_name="MyRAGAssistant")
print(assistant)

Where:

  • assistant_name: (Required) Name of the RAG Assistant.

Returns: A RAGAssistant instance with the Assistant’s details, or an error response.

Upload Document

Uploads a document to a RAG Assistant for indexing and retrieval.

1. Command Line

You can upload a document using the following Command Line options:

geai rag upload-document 
  -n "MyRAGAssistant" 
  -f "/path/to/document.pdf" 
  --content-type "application/pdf" 
  --upload-type "multipart"

Where:

  • -n, --name: (Required) Name of the RAG Assistant.
  • -f, --file-path: (Required) Path to the document file.
  • --content-type, --ct: MIME type of the document (e.g., "application/pdf").
  • --upload-type, -t: Upload method ("multipart" or "binary", defaults to "multipart").
  • --metadata, -m: Optional metadata (JSON or file path, for multipart uploads).

2. Low-Level Service Layer

Use the following code snippet to upload a document using the Low-Level Service Layer:

client = RAGAssistantClient()
result = client.upload_document(
    name="MyRAGAssistant",
    file_path="/path/to/document.pdf",
    content_type="application/pdf",
    upload_type="multipart",
    metadata={"author": "John Doe"}
)
print(result)

Where:

  • name: (Required) Name of the RAG Assistant.
  • file_path: (Required) Path to the document file.
  • content_type: MIME type (e.g., "application/pdf").
  • upload_type: "multipart" or "binary" (defaults to "multipart").
  • metadata: Optional metadata dictionary or file path (for multipart).

Returns: A dictionary containing the API response with details of the uploaded document.

3. High-Level Service Layer

Use the following code snippet to upload a document using the High-Level Service Layer:

from pygeai.assistant.rag.models import RAGAssistant, UploadDocument

manager = AssistantManager()
assistant = RAGAssistant(name="MyRAGAssistant")
document = UploadDocument(
    path="/path/to/document.pdf",
    content_type="application/pdf",
    upload_type="multipart",
    metadata={"author": "John Doe"}
)
result = manager.upload_document(assistant, document)
print(result)

Where:

  • RAGAssistant: Specifies the target assistant.
  • UploadDocument: Defines the document properties.
  • AssistantManager: Manages upload and response mapping.

Returns: A Document instance representing the uploaded document, or an error response.

Retrieve Document

Retrieves a specific document from a RAG Assistant by its ID.

1. Command Line

You can retrieve a document using the following Command Line options:

geai rag get-document -n "MyRAGAssistant" --document-id "doc123"

Where:

  • -n, --name: (Required) Name of the RAG Assistant.
  • --document-id, --id: (Required) Document ID.

2. Low-Level Service Layer

Use the following code snippet to retrieve a document using the Low-Level Service Layer:

client = RAGAssistantClient()
document = client.retrieve_document(name="MyRAGAssistant", document_id="doc123")
print(document)

Where:

  • name: (Required) Name of the RAG Assistant.
  • document_id: (Required) Document ID.

Returns: A dictionary containing the document’s details.

3. High-Level Service Layer

Use the following code snippet to retrieve a document using the High-Level Service Layer:

from pygeai.assistant.managers import AssistantManager

manager = AssistantManager()
document = manager.get_document(name="MyRAGAssistant", document_id="doc123")
print(document)

Where:

  • name: (Required) Name of the RAG Assistant.
  • document_id: (Required) Document ID.

Returns: A Document instance with the document’s details, or an error response.

List Documents

Lists documents associated with a RAG Assistant, with optional pagination.

1. Command Line

You can list documents using the following Command Line options:

geai rag list-documents -n "MyRAGAssistant" --skip 0 --count 10

Where:

  • -n, --name: (Required) Name of the RAG Assistant.
  • --skip, -s: Number of documents to skip (default: 0).
  • --count, -c: Number of documents to return (default: 10).

2. Low-Level Service Layer

Use the following code snippet to list documents using the Low-Level Service Layer:

client = RAGAssistantClient()
documents = client.get_documents(name="MyRAGAssistant", skip=0, count=10)
print(documents)

Where:

  • name: (Required) Name of the RAG Assistant.
  • skip: Number of documents to skip (default: 0).
  • count: Number of documents to return (default: 10).

Returns: A dictionary containing a list of documents.

3. High-Level Service Layer

Use the following code snippet to list documents using the High-Level Service Layer:

from pygeai.assistant.managers import AssistantManager

manager = AssistantManager()
documents = manager.get_document_list(name="MyRAGAssistant", skip=0, count=10)
print(documents)

Where:

  • name: (Required) Name of the RAG Assistant.
  • skip: Number of documents to skip (default: 0).
  • count: Number of documents to return (default: 10).

Returns: A DocumentListResponse containing the list of documents, or an error response.

Delete Document

Deletes a specific document from a RAG Assistant by its ID.

1. Command Line

You can delete a document using the following Command Line options:

geai rag delete-document -n "MyRAGAssistant" --document-id "doc123"

Where:

  • -n, --name: (Required) Name of the RAG Assistant.
  • --document-id, --id: (Required) Document ID.

2. Low-Level Service Layer

Use the following code snippet to delete a document using the Low-Level Service Layer:

client = RAGAssistantClient()
result = client.delete_document(name="MyRAGAssistant", document_id="doc123")
print(result)

Where:

  • name: (Required) Name of the RAG Assistant.
  • document_id: (Required) Document ID.

Returns: A dictionary indicating deletion success or failure.

3. High-Level Service Layer

Use the following code snippet to delete a document using the High-Level Service Layer:

from pygeai.assistant.managers import AssistantManager

manager = AssistantManager()
result = manager.delete_document(name="MyRAGAssistant", document_id="doc123")
print(result)

Where:

  • name: (Required) Name of the RAG Assistant.
  • document_id: (Required) Document ID.

Returns: An EmptyResponse indicating success, or an error response.

Delete All Documents

Deletes all documents associated with a RAG Assistant.

1. Command Line

You can delete all documents using the following Command Line options:

geai rag delete-all-documents -n "MyRAGAssistant"

Where:

  • -n, --name: (Required) Name of the RAG Assistant.

2. Low-Level Service Layer

Use the following code snippet to delete all documents using the Low-Level Service Layer:

client = RAGAssistantClient()
result = client.delete_all_documents(name="MyRAGAssistant")
print(result)

Where:

  • name: (Required) Name of the RAG Assistant.

Returns: A dictionary indicating deletion success or failure.

3. High-Level Service Layer

Use the following code snippet to delete all documents using the High-Level Service Layer:

from pygeai.assistant.managers import AssistantManager

manager = AssistantManager()
result = manager.delete_all_documents(name="MyRAGAssistant")
print(result)

Where:

  • name: (Required) Name of the RAG Assistant.

Returns: An EmptyResponse indicating success, or an error response.

Execute Query

Executes a query against the RAG Assistant’s indexed documents.

1. Command Line

You can execute a query using the following Command Line options:

geai rag execute-query -n "MyRAGAssistant" --query '{"query": "What is AI?"}'

Where:

  • -n, --name: (Required) Name of the RAG Assistant.
  • --query: (Required) JSON query string.

2. Low-Level Service Layer

Use the following code snippet to execute a query using the Low-Level Service Layer:

client = RAGAssistantClient()
query = {"query": "What is AI?"}
result = client.execute_query(query=query)
print(result)

Where:

  • query: (Required) Dictionary containing the query details.

Returns: A dictionary containing the query results.

3. High-Level Service Layer

from pygeai.assistant.managers import AssistantManager

manager = AssistantManager()
query = {"query": "What is AI?"}
result = manager.execute_query(query=query)  # Note: Manager may not directly support execute_query; use client
print(result)
Note: The high-level AssistantManager does not explicitly expose execute_query. Use RAGAssistantClient for this functionality.

Returns: A dictionary containing the query results, or an error response.

Notes

  • Command Line provides a user-friendly interface with parameters for all configuration options.
  • The Low-Level Client (RAGAssistantClient) offers fine-grained control over API calls, ideal for custom integrations.
  • The High-Level Manager (AssistantManager) simplifies operations by handling response mapping and error processing, suitable for robust applications.
  • Error handling in both low-level and high-level layers manages JSON decoding errors and API errors, returning structured responses.
  • Search, index, and welcome data options are highly customizable for tailored assistant behavior.

Availability

Since version 2025-05.

Last update: December 2025 | © GeneXus. All rights reserved. GeneXus Powered by Globant