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:
- Command Line
- Low-Level Service Layer
- High-Level Service Layer
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.
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.
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.
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.
Updates an existing RAG Assistant’s status, description, template, search options, or welcome data. The Assistant name and status are required.
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.
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.
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.
Deletes an existing RAG Assistant by name.
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.
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.
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.
Retrieves all RAG Assistants in a Project.
You can list RAG Assistants using the following Command Line options:
geai rag list-assistants
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.
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.
Retrieves details of a specific RAG Assistant by name.
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.
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.
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.
Uploads a document to a RAG Assistant for indexing and retrieval.
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).
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.
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.
Retrieves a specific document from a RAG Assistant by its ID.
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.
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.
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.
Lists documents associated with a RAG Assistant, with optional pagination.
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).
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.
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.
Deletes a specific document from a RAG Assistant by its ID.
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.
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.
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.
Deletes all documents associated with a RAG Assistant.
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.
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.
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.
Executes a query against the RAG Assistant’s indexed documents.
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.
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.
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.
- 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.
Since version 2025-05.