Search knowledge base
curl --request POST \
--url https://api.lehar.ai/ca/api/v0/knowledge-base/search \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"query": "when are you open",
"knowledge_base_id": "kb_01jq8x9m2h4z7c0r5v3b8t6n1e",
"top_k": 3
}
'import requests
url = "https://api.lehar.ai/ca/api/v0/knowledge-base/search"
payload = {
"query": "when are you open",
"knowledge_base_id": "kb_01jq8x9m2h4z7c0r5v3b8t6n1e",
"top_k": 3
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
query: 'when are you open',
knowledge_base_id: 'kb_01jq8x9m2h4z7c0r5v3b8t6n1e',
top_k: 3
})
};
fetch('https://api.lehar.ai/ca/api/v0/knowledge-base/search', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.lehar.ai/ca/api/v0/knowledge-base/search",
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([
'query' => 'when are you open',
'knowledge_base_id' => 'kb_01jq8x9m2h4z7c0r5v3b8t6n1e',
'top_k' => 3
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.lehar.ai/ca/api/v0/knowledge-base/search"
payload := strings.NewReader("{\n \"query\": \"when are you open\",\n \"knowledge_base_id\": \"kb_01jq8x9m2h4z7c0r5v3b8t6n1e\",\n \"top_k\": 3\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
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))
}HttpResponse<String> response = Unirest.post("https://api.lehar.ai/ca/api/v0/knowledge-base/search")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"when are you open\",\n \"knowledge_base_id\": \"kb_01jq8x9m2h4z7c0r5v3b8t6n1e\",\n \"top_k\": 3\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.lehar.ai/ca/api/v0/knowledge-base/search")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"query\": \"when are you open\",\n \"knowledge_base_id\": \"kb_01jq8x9m2h4z7c0r5v3b8t6n1e\",\n \"top_k\": 3\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"id": "b7e6f0a4-2c1d-5f3a-9b8c-1d2e3f4a5b6c",
"question": "What are your support hours?",
"response": "Our team is available 9am to 6pm IST, Monday to Friday.",
"knowledge_base_id": "kb_01jq8x9m2h4z7c0r5v3b8t6n1e",
"match_percentage": 92.5
}
]
}{
"error": {
"code": "invalid_request",
"message": "query is required"
}
}{
"error": {
"code": "unauthorized",
"message": "Authentication required"
}
}{
"error": {
"code": "forbidden",
"message": "Scope 'knowledge_base:read' is required"
}
}{
"error": {
"code": "internal_error",
"message": "An unexpected error occurred"
}
}{
"error": {
"code": "service_unavailable",
"message": "Knowledge base service is not configured"
}
}Knowledge Base
Search knowledge base
Semantic search over one knowledge base’s Q&A rows, returning the closest matches ranked by a match percentage (the document plane; the singular /knowledge-base path). This is the one document-plane endpoint agent-session tokens may call. Scope knowledge_base:read.
POST
/
knowledge-base
/
search
Search knowledge base
curl --request POST \
--url https://api.lehar.ai/ca/api/v0/knowledge-base/search \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"query": "when are you open",
"knowledge_base_id": "kb_01jq8x9m2h4z7c0r5v3b8t6n1e",
"top_k": 3
}
'import requests
url = "https://api.lehar.ai/ca/api/v0/knowledge-base/search"
payload = {
"query": "when are you open",
"knowledge_base_id": "kb_01jq8x9m2h4z7c0r5v3b8t6n1e",
"top_k": 3
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
query: 'when are you open',
knowledge_base_id: 'kb_01jq8x9m2h4z7c0r5v3b8t6n1e',
top_k: 3
})
};
fetch('https://api.lehar.ai/ca/api/v0/knowledge-base/search', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.lehar.ai/ca/api/v0/knowledge-base/search",
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([
'query' => 'when are you open',
'knowledge_base_id' => 'kb_01jq8x9m2h4z7c0r5v3b8t6n1e',
'top_k' => 3
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.lehar.ai/ca/api/v0/knowledge-base/search"
payload := strings.NewReader("{\n \"query\": \"when are you open\",\n \"knowledge_base_id\": \"kb_01jq8x9m2h4z7c0r5v3b8t6n1e\",\n \"top_k\": 3\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
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))
}HttpResponse<String> response = Unirest.post("https://api.lehar.ai/ca/api/v0/knowledge-base/search")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"when are you open\",\n \"knowledge_base_id\": \"kb_01jq8x9m2h4z7c0r5v3b8t6n1e\",\n \"top_k\": 3\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.lehar.ai/ca/api/v0/knowledge-base/search")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"query\": \"when are you open\",\n \"knowledge_base_id\": \"kb_01jq8x9m2h4z7c0r5v3b8t6n1e\",\n \"top_k\": 3\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"id": "b7e6f0a4-2c1d-5f3a-9b8c-1d2e3f4a5b6c",
"question": "What are your support hours?",
"response": "Our team is available 9am to 6pm IST, Monday to Friday.",
"knowledge_base_id": "kb_01jq8x9m2h4z7c0r5v3b8t6n1e",
"match_percentage": 92.5
}
]
}{
"error": {
"code": "invalid_request",
"message": "query is required"
}
}{
"error": {
"code": "unauthorized",
"message": "Authentication required"
}
}{
"error": {
"code": "forbidden",
"message": "Scope 'knowledge_base:read' is required"
}
}{
"error": {
"code": "internal_error",
"message": "An unexpected error occurred"
}
}{
"error": {
"code": "service_unavailable",
"message": "Knowledge base service is not configured"
}
}Authorizations
ApiKeyAuthBearerAuth
Body
application/json
Natural-language search text. Required and non-empty (trimmed).
Knowledge base to search. Required; a KB id outside the caller's workspace simply matches zero documents (no cross-tenant leak).
Number of matches to return. Defaults to 3; must be an integer between 1 and 10.
Required range:
1 <= x <= 10Response
Matches ordered best-first. match_percentage is the similarity score scaled to 0-100. Returns an empty data array when nothing matches (including when the KB is empty or belongs to another workspace).

