Search through all files in data folders shared with the API Key
curl --request POST \
--url https://api.langdock.com/knowledge/search \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "API Documentation"
}
'import requests
url = "https://api.langdock.com/knowledge/search"
payload = { "query": "API Documentation" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({query: 'API Documentation'})
};
fetch('https://api.langdock.com/knowledge/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.langdock.com/knowledge/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' => 'API Documentation'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.langdock.com/knowledge/search"
payload := strings.NewReader("{\n \"query\": \"API Documentation\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.langdock.com/knowledge/search")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"API Documentation\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/knowledge/search")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"query\": \"API Documentation\"\n}"
response = http.request(request)
puts response.read_bodyKnowledge Folder API
Wissensdatenbank durchsuchen
Führe eine semantische Suche über Wissensdatenbanken durch, die mit deinem API-Schlüssel geteilt sind
POST
/
knowledge
/
search
Search through all files in data folders shared with the API Key
curl --request POST \
--url https://api.langdock.com/knowledge/search \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"query": "API Documentation"
}
'import requests
url = "https://api.langdock.com/knowledge/search"
payload = { "query": "API Documentation" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({query: 'API Documentation'})
};
fetch('https://api.langdock.com/knowledge/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.langdock.com/knowledge/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' => 'API Documentation'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.langdock.com/knowledge/search"
payload := strings.NewReader("{\n \"query\": \"API Documentation\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.langdock.com/knowledge/search")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"query\": \"API Documentation\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/knowledge/search")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"query\": \"API Documentation\"\n}"
response = http.request(request)
puts response.read_bodyFührt eine semantische Suche über alle Wissensdatenbanken durch, die mit deinem API-Schlüssel geteilt sind. Gibt relevante Dokumentenabschnitte zurück, sortiert nach Ähnlichkeit zu deiner Suchanfrage.
Bevor du startest
- API-Key-Scope: Erfordert einen API-Schlüssel mit dem
KNOWLEDGE_FOLDER_APIScope. Die Suche umfasst alle Wissensdatenbanken, die mit dem API-Schlüssel geteilt sind. Siehe Wissensdatenbank mit der API teilen für die Einrichtung.
Basis-URL
https://api.langdock.com
Dedicated DeploymentsErsetze
api.langdock.com durch <your-deployment-url>/api/public in allen Anfragen.Wie es funktioniert
- Deine Suchanfrage wird mit dem Standard-Embedding-Modell deines Workspace in ein Embedding umgewandelt
- Das System führt eine Vektor-Ähnlichkeitssuche über alle Dokumente in geteilten Wissensdatenbankenn durch
- Ergebnisse werden nach Relevanzschwelle gefiltert und mit einem LLM neu bewertet
- Nur der am höchsten bewertete Abschnitt pro Dokument wird zurückgegeben
Anforderungsformat
Request Body
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
query | string | Ja | Die Suchanfrage zum Finden relevanter Dokumente |
Beispiele
Suche mit cURL
curl -X POST "https://api.langdock.com/knowledge/search" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "Was sind die Q4 Umsatzprognosen?"}'
Suche mit JavaScript
const axios = require("axios");
async function searchKnowledge(query) {
const response = await axios.post(
"https://api.langdock.com/knowledge/search",
{ query },
{
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
}
);
return response.data;
}
// Beispiel
const results = await searchKnowledge("Was sind die Q4 Umsatzprognosen?");
console.log(`${results.result.length} relevante Dokumente gefunden`);
results.result.forEach((chunk, i) => {
console.log(`\n--- Ergebnis ${i + 1} ---`);
console.log(`Datei: ${chunk.subname}`);
console.log(`Ähnlichkeit: ${(chunk.similarity * 100).toFixed(1)}%`);
console.log(`Text: ${chunk.text.substring(0, 200)}...`);
});
Suchergebnisse für RAG verwenden
async function answerWithContext(question) {
// Nach relevantem Kontext suchen
const searchResults = await searchKnowledge(question);
// Kontext aus Suchergebnissen erstellen
const context = searchResults.result
.map((chunk) => `Quelle: ${chunk.subname}\n${chunk.text}`)
.join("\n\n---\n\n");
// Kontext mit deinem LLM verwenden
const prompt = `Basierend auf dem folgenden Kontext, beantworte die Frage.
Kontext:
${context}
Frage: ${question}
Antwort:`;
// Deinen bevorzugten LLM-Endpunkt aufrufen
return callLLM(prompt);
}
Antwortformat
Erfolgreiche Antwort (200 OK)
{
status: "success";
result: Array<{
id: string; // Eindeutige Chunk-ID
text: string; // Der Textinhalt des Chunks
similarity: number; // Ähnlichkeitswert (0-1)
subsource: string; // Attachment-ID
subname: string; // Dateiname
url: string | null; // Quell-URL, falls beim Upload angegeben
index: number; // Ergebnisindex (0-basiert)
}>;
}
Beispielantwort
{
"status": "success",
"result": [
{
"id": "chunk_abc123",
"text": "Q4 Umsatzprognosen zeigen einen Anstieg von 15% im Vergleich zu Q3, hauptsächlich getrieben durch starke Enterprise-Verkäufe in der EMEA-Region...",
"similarity": 0.89,
"subsource": "att_xyz789",
"subname": "quartalsbericht-2024.pdf",
"url": "https://example.com/reports/q4-2024",
"index": 0
},
{
"id": "chunk_def456",
"text": "Der prognostizierte Umsatz für das vierte Quartal berücksichtigt saisonale Trends und die Auswirkungen neuer Produkteinführungen...",
"similarity": 0.82,
"subsource": "att_abc456",
"subname": "finanzprognose.docx",
"url": null,
"index": 1
}
]
}
Fehlerbehandlung
try {
const response = await searchKnowledge(query);
} catch (error) {
if (error.response) {
switch (error.response.status) {
case 400:
console.error("Ungültige Anfrage:", error.response.data.message);
break;
case 401:
console.error("Ungültiger oder fehlender API-Schlüssel");
break;
case 403:
console.error("API-Schlüssel hat keinen KNOWLEDGE_FOLDER_API Scope");
break;
case 429:
console.error("Rate Limit überschritten");
break;
case 500:
console.error("Server-Fehler");
break;
}
}
}
Best Practices
Schreibe klare, spezifische Suchanfragen — Die Suche verwendet semantische Ähnlichkeit, daher funktionieren natürlichsprachliche Fragen gut. Sei spezifisch bei dem, was du suchst. Behandle leere Ergebnisse — Wenn keine relevanten Dokumente gefunden werden, ist dasresult Array leer. Deine Anwendung sollte dies entsprechend behandeln.
Nutze Ähnlichkeitswerte — Der similarity Wert reicht von 0 bis 1. Höhere Werte bedeuten bessere Übereinstimmungen. Erwäge, Ergebnisse unter einem bestimmten Schwellenwert für deinen Anwendungsfall zu filtern.
Quellenangaben — Verwende die subname und url Felder, um Quellenangaben zu machen, wenn du Ergebnisse für Nutzer anzeigst.
Langdock blockiert bewusst Browser-basierte Anfragen, um deinen API-Schlüssel zu schützen und die Sicherheit deiner Anwendungen zu gewährleisten. Weitere Informationen findest du in unserem Guide zu Best Practices für API-Schlüssel.
War diese Seite hilfreich?