RAG use case
import requests
url = "https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}"
payload = { "batch": [
{
"text": "Why did I go to Germany?",
"documents": [
{
"body": "I'm off to Germany to go to the Oktoberfest!",
"source": "http://example.com/112",
"title": "Off to Germany!",
"date": "2022-01-31T19:31:34Z"
}
]
}
] }
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)HttpResponse<String> response = Unirest.post("https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"batch\": [\n {\n \"text\": \"Why did I go to Germany?\",\n \"documents\": [\n {\n \"body\": \"I'm off to Germany to go to the Oktoberfest!\",\n \"source\": \"http://example.com/112\",\n \"title\": \"Off to Germany!\",\n \"date\": \"2022-01-31T19:31:34Z\"\n }\n ]\n }\n ]\n}")
.asString();const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
batch: [
{
text: 'Why did I go to Germany?',
documents: [
{
body: JSON.stringify('I\'m off to Germany to go to the Oktoberfest!'),
source: 'http://example.com/112',
title: 'Off to Germany!',
date: '2022-01-31T19:31:34Z'
}
]
}
]
})
};
fetch('https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));require 'uri'
require 'net/http'
url = URI("https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"batch\": [\n {\n \"text\": \"Why did I go to Germany?\",\n \"documents\": [\n {\n \"body\": \"I'm off to Germany to go to the Oktoberfest!\",\n \"source\": \"http://example.com/112\",\n \"title\": \"Off to Germany!\",\n \"date\": \"2022-01-31T19:31:34Z\"\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_bodypackage main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}"
payload := strings.NewReader("{\n \"batch\": [\n {\n \"text\": \"Why did I go to Germany?\",\n \"documents\": [\n {\n \"body\": \"I'm off to Germany to go to the Oktoberfest!\",\n \"source\": \"http://example.com/112\",\n \"title\": \"Off to Germany!\",\n \"date\": \"2022-01-31T19:31:34Z\"\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'batch' => [
[
'text' => 'Why did I go to Germany?',
'documents' => [
[
'body' => 'I\'m off to Germany to go to the Oktoberfest!',
'source' => 'http://example.com/112',
'title' => 'Off to Germany!',
'date' => '2022-01-31T19:31:34Z'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}curl --request POST \
--url https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID} \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"batch": [
{
"text": "Why did I go to Germany?",
"documents": [
{
"body": "I'm off to Germany to go to the Oktoberfest!",
"source": "http://example.com/112",
"title": "Off to Germany!",
"date": "2022-01-31T19:31:34Z"
}
]
}
]
}
EOF{
"predictions": [
{
"tokensUsed": {
"promptTokens": 606,
"completionTokens": 23,
"totalTokens": 629
},
"answer": "The reason for going to Germany was to attend Oktoberfest.",
"answerFound": true,
"sources": [
"http://example.com/112"
],
"memoryUuid": "53417d2f-6b0e-47e4-8610-e6842b84a87b",
"response": "SOURCES:\n- 0\nANSWER: The reason for going to Germany was to attend Oktoberfest."
}
]
}RAG use case
The rag use case uses candidate documents that are inserted into a LLM’s context to ground the generated response to those documents instead of generating an answer from details stored in the LLM’s trained weights. This type of search adds guardrails so the LLM can search private data collections.
The RAG search can perform queries against external documents passed in as part of the request.
POST
/
ai
/
prediction
/
rag
/
{MODEL_ID}
RAG use case
import requests
url = "https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}"
payload = { "batch": [
{
"text": "Why did I go to Germany?",
"documents": [
{
"body": "I'm off to Germany to go to the Oktoberfest!",
"source": "http://example.com/112",
"title": "Off to Germany!",
"date": "2022-01-31T19:31:34Z"
}
]
}
] }
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)HttpResponse<String> response = Unirest.post("https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"batch\": [\n {\n \"text\": \"Why did I go to Germany?\",\n \"documents\": [\n {\n \"body\": \"I'm off to Germany to go to the Oktoberfest!\",\n \"source\": \"http://example.com/112\",\n \"title\": \"Off to Germany!\",\n \"date\": \"2022-01-31T19:31:34Z\"\n }\n ]\n }\n ]\n}")
.asString();const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
batch: [
{
text: 'Why did I go to Germany?',
documents: [
{
body: JSON.stringify('I\'m off to Germany to go to the Oktoberfest!'),
source: 'http://example.com/112',
title: 'Off to Germany!',
date: '2022-01-31T19:31:34Z'
}
]
}
]
})
};
fetch('https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));require 'uri'
require 'net/http'
url = URI("https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"batch\": [\n {\n \"text\": \"Why did I go to Germany?\",\n \"documents\": [\n {\n \"body\": \"I'm off to Germany to go to the Oktoberfest!\",\n \"source\": \"http://example.com/112\",\n \"title\": \"Off to Germany!\",\n \"date\": \"2022-01-31T19:31:34Z\"\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_bodypackage main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}"
payload := strings.NewReader("{\n \"batch\": [\n {\n \"text\": \"Why did I go to Germany?\",\n \"documents\": [\n {\n \"body\": \"I'm off to Germany to go to the Oktoberfest!\",\n \"source\": \"http://example.com/112\",\n \"title\": \"Off to Germany!\",\n \"date\": \"2022-01-31T19:31:34Z\"\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'batch' => [
[
'text' => 'Why did I go to Germany?',
'documents' => [
[
'body' => 'I\'m off to Germany to go to the Oktoberfest!',
'source' => 'http://example.com/112',
'title' => 'Off to Germany!',
'date' => '2022-01-31T19:31:34Z'
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}curl --request POST \
--url https://{APPLICATION_ID}.applications.lucidworks.com/ai/prediction/rag/{MODEL_ID} \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"batch": [
{
"text": "Why did I go to Germany?",
"documents": [
{
"body": "I'm off to Germany to go to the Oktoberfest!",
"source": "http://example.com/112",
"title": "Off to Germany!",
"date": "2022-01-31T19:31:34Z"
}
]
}
]
}
EOF{
"predictions": [
{
"tokensUsed": {
"promptTokens": 606,
"completionTokens": 23,
"totalTokens": 629
},
"answer": "The reason for going to Germany was to attend Oktoberfest.",
"answerFound": true,
"sources": [
"http://example.com/112"
],
"memoryUuid": "53417d2f-6b0e-47e4-8610-e6842b84a87b",
"response": "SOURCES:\n- 0\nANSWER: The reason for going to Germany was to attend Oktoberfest."
}
]
}Headers
Body
application/json
Was this page helpful?