AI Powered Datafari API
Valid from Datafari 6.2
Introduction
This feature is a work-in-progress and experimental collection of API endpoints, that should be added to Datafari API.
See our RAG feature: Datafari RagAPI - RAG . As RAG is considered as a part as the search process, it is not included in the AiPowered API. However, both share common elements, such as configuration.
Configuration
Before using the AiPowered endpoint, your Datafari needs to be properly configured. Use the “RAG & AI configuration” AdminUI to set up your environment. You will also need an AI web service that can run Large Language Models.
Prefix
Every endpoint in this API are prefixed by /rest/v2.0/ai
.
Do also remember to add the relevant path to your Datafari web app (https://[datafaridomain]/Datafari/rest/v2.0/ai/[endpoint]
)
Response format
Responses may differ depending on the endpoint. All responses are JSON.
{
"status":"OK",
"content": {
...
}
}
This is the template for error responses:
{
"status":"ERROR",
"content":{
"message":"...",
"documents": [],
"error":{
"code":...,
"label":"...",
"message": "..."
}
}
}
The “content” provides a default responses in English that can be displayed as a chatbot. However, since its “message” is not localized, we recommend using “error.label” as a translation key to display a message in the proper language.
The “error.message” field is only used in case of exceptions, and provides a technical description of the incident.
Field | Description |
---|---|
|
|
| The generated response of the LLM to be displayed to the user. |
| An array, always present to maintain response structure. It can be empty, or contain a list of documents (e.g. sources used by the LLM to generate a RAG response) |
| Numeric error code, for internal or programmatic handling |
| Translation key, to display a localized user-friendly message (instead of the |
| Technical error description. Optional, not user friendly. |
Above is the list of the existing error labels, with their associated default message (in English):
ragErrorNotEnabled: Sorry, it seems the feature is not enabled.
ragNoFileFound: Sorry, I couldn't find any relevant document to answer your request.
ragTechnicalError: Sorry, I met a technical issue. Please try again later, and if the problem remains, contact an administrator.
ragNoValidAnswer: Sorry, I could not find an answer to your question.
ragBadRequest: Sorry, It appears there is an issue with the request. Please try again later, and if the problem remains, contact an administrator.
summarizationErrorNotEnabled: Sorry, it seems the feature is not enabled.
summarizationNoFileFound: Sorry, I cannot find this document.
summarizationTechnicalError: Sorry, I met a technical issue. Please try again later, and if the problem remains, contact an administrator.
summarizationBadRequest: Sorry, It appears there is an issue with the request. Please try again later, and if the problem remains, contact an administrator.
summarizationEmptyFile: Sorry, I am unable to generate a summary, since the file has no content.
Endpoints
All available AiPower API endpoint are documented here.
Method | Endpoint | Description |
---|---|---|
POST | /summarize | Returns the summary of a Solr documents if it exists, or generate it otherwise. |
RAG | /rag | Process a RAG search. If ID is provided, only the associated document is used for information retrieval. |
POST /summarize
Returns the summary of a Solr documents if it exists, or generate it otherwise. The Solr is retrieved from the FileShare collection using Datafari search, so the security is maintained.
REQUEST
POST https://[datafaridomain]/Datafari/rest/v2.0/ai/summarize
Request body:
{
"id": "[any_solr_document_id]",
"lang": "[language_code]"
}
RESPONSE
POST https://[datafaridomain]/Datafari/rest/v2.0/ai/summarize
Response body:
{
"content": {
"message": "The document provides detailed financial information and ...[truncated]... & Trade Resources."
}
"status":"OK"
}
Parameters
Name | Description | Optional ? (Default value) |
---|---|---|
id | The Solr ID of the document to summarize. | No |
lang | The code of the expected response language. | Yes ( |
Processing details
As most documents are too large to be processed at once by a Large Language Model, the service requires a chunking solution.
Document is retrieved from Solr by its ID, using Datafari search.
The document content is extracted from field
exactContent
.The content is chunked into smaller sub-documents. Chunk size (in characters) can be configured in the AdminUI (RAG & AI configuration), or in
rag.properties
by setting thechunking.chunk.size
property.Each document is sent to a LLM for summarization.
The LLM is sent one more time (if needed) the generate a global summary from its previous responses.
The summary generation can be disabled from the “RAG & AI configuration” AdminUI, or by directly setting ai.summarization.enabled
attribute to false
in rag.properties
.
POST /rag
Processes a RAG (Retrieval Augmented Generation) request. The LLM generates a response to the user query/question, based on retrieved documents.
REQUEST
POST https://[datafaridomain]/Datafari/rest/v2.0/ai/rag
Request body:
{
"query": "[user_query]",
"id": "[any_solr_document_id]",
"lang": "[language_code]",
"history": []
}
Or
{
"query": "[user_query]",
"lang": "[language_code]",
"history": []
}
RESPONSE
POST https://[datafaridomain]/Datafari/rest/v2.0/ai/rag
Response body:
{
"status": "OK|ERROR",
"content": {
"message": "...",
"documents": [
{
"url": "...",
"id": "...",
"title": "...",
"content": "..."
},
{
"url": "...",
"id": "...",
"title": "...",
"content": "..."
},
...
]
}
}
Parameters
Name | Description | Optional ? (Default value) |
---|---|---|
query | The user query. | No |
id | A file ID. If the ID is set, the LLM will only use the associated document (if any) to answer the user query. | Yes (none) |
lang | The code of the expected response language. | Yes ( |
history | If Chat Memory is enable, the “history” field can take a list of messages to keep track of the chat history. See Datafari RagAPI - RAG | Chat Memory (for RAG) to use Chat Memory. | Yes (none) |
Processing details
As most documents are too large to be processed at once by a Large Language Model, the service requires a chunking solution.
History retrieval. If “chat memory” is enabled (from AdminUI or rag.properties), the chat history is retrieved to be used in the prompts.
Source retrieval. Documents are retrieved from Solr using Datafari search.
If the “id” field is set, only the associated document will be retrieved.
The retrieval step can use Vector Search, or BM25 Search. This can be configured in AdminUI or in rag.properties (solr.enable.vector.search
totrue
orfalse
).
Optional : If thechat.query.rewriting.enabled
property is enabled, the search query is rewritten by the LLM before the Solr search. This only applies to the search step. The initial user query is still used in RAG process. If enabled, the history is used for query rewriting.RAG processing. The documents are processed by RagAPI.
Chunking : Any document content (or document extract, in case of vector search) larger than the maximum chunk size defined in AdminUI/rag.properties (
chunking.chunk.size
) is chunked into smaller pieces.Prompting : The relevant prompts for the AI model are prepared in
PromptUtils
. Prompt templates can be edited in:/opt/datafari/tomcat/webapps/Datafari/WEB-INF/classes/prompts
Response generation: the prepared prompts are send to an external LLM API, using an LlmService.
Depending on the the number and size of the chunks, it make takes several LLM requests to process them all. The chunk management stategy (Map-Reduce or Iterative Refining) can be selected in the AdminUI.
The response is formatted and returned.
See Datafari RagAPI - RAG documentation for more information about RAG processes.