Logo
Search & Inference

Knowledge Search

Overview

The Knowledge Search endpoint is an intelligent document search and question-answering system powered by AI that provides accurate answers from your knowledge base with source citations. It uses advanced natural language processing to understand questions and retrieve relevant information from your uploaded documents.

Use this endpoint to:

  • Ask natural language questions about your documents
  • Extract specific information with AI-powered search
  • Get answers with source citations and page references
  • Build intelligent chatbots and Q&A systems
  • Implement document-based knowledge retrieval in your applications

Endpoint Details

Method: POST
Endpoint: /api/agent/k_search
Base URL: https://api.k-v.ai
Authentication: Access Key (Required)


Request Specification

Headers

HeaderTypeRequiredDescription
access-keystringYesYour unique access-key generated from the platform UI
Content-TypestringYesMust be application/json

Request Body

{
    "doc_process_ids": ["264dfa262b748d15ccbeaada89430c68"],
    "question": "What are the parties involved?",
    "context": "concise",
    "model_data": {
        "model_name": "gpt-5.1",
        "api_key": ""
    }
}

Body Fields

FieldTypeRequiredDescription
doc_process_idsarrayYesArray of document IDs to search within (obtained from Upload or List Documents APIs)
questionstringYesNatural language question to ask about your documents
contextstringNoResponse detail level: concise, medium, or extended (default: medium)
model_dataobjectYesAI model configuration
model_data.model_namestringYesAI model to use for processing (see supported models below)
model_data.api_keystringNoYour own LLM API key (leave empty to use platform's default keys)

Supported AI Models

Model NameProvider
gpt-5.1OpenAI
gpt-5-miniOpenAI
claude-sonnet-4-5-20250929Anthropic
gemini/gemini-2.5-flash-liteGoogle
gemini/gemini-2.5-proGoogle
gemini/gemini-3-pro-previewGoogle
mistral/mistral-small-latestMistral AI
mistral/mistral-medium-latestMistral AI
llama3.1-70bMeta

Context Levels

ContextDescription
conciseBrief, direct answer with key points only
mediumBalanced response with explanations
extendedComprehensive detailed analysis

Using Your Own LLM API Keys

Platform Keys (Default)

{
    "model_data": {
        "model_name": "gpt-5.1",
        "api_key": ""
    }
}

Your Own Keys

{
    "model_data": {
        "model_name": "gpt-5.1",
        "api_key": "sk-your-openai-api-key-here"
    }
}

Response Specification

Success Response (200 OK)

{
    "data": {
        "answer": "The parties involved are:\n\n- **ABC Software Corporation** (referred to as the **Plaintiff**)  \n- **Widget Corporation** (referred to as the **Defendant**)",
        "sources": [
            {
                "content": "SETTLEMENT AGREEMENT AND RELEASE...",
                "score": 0.38453761232252937,
                "filename": "Settlement Agreement (1).pdf",
                "doc_hash": "264dfa262b748d15ccbeaada89430c68",
                "page_number": 1
            }
        ]
    },
    "message": "Question processed successfully"
}

Response Fields

FieldTypeDescription
dataobjectResponse data object
data.answerstringAI-generated answer to your question with citations
data.sourcesarrayArray of source excerpts used to generate the answer
data.sources[].contentstringRelevant text excerpt from the document
data.sources[].scorefloatRelevance score
data.sources[].filenamestringOriginal filename of the source document
data.sources[].doc_hashstringDocument process ID (same as doc_process_id)
data.sources[].page_numberintegerPage number where the content was found
messagestringHuman-readable response message

Error Responses

401 Unauthorized

{
    "data": {},
    "message": "Invalid or missing access key"
}

Cause: Missing or invalid access-key header.


422 Unprocessable Entity - Invalid Context

{
    "detail": [
        {
            "type": "literal_error",
            "loc": [
                "body",
                "context"
            ],
            "msg": "Input should be 'concise', 'medium' or 'extended'",
            "input": "",
            "ctx": {
                "expected": "'concise', 'medium' or 'extended'"
            }
        }
    ]
}

Cause: Invalid value for context parameter. Must be one of: concise, medium, or extended.


422 Unprocessable Entity - Invalid Model Name

{
    "detail": [
        {
            "type": "literal_error",
            "loc": [
                "body",
                "model_data",
                "model_name"
            ],
            "msg": "Input should be 'gpt-5-chat-latest', 'gpt-5.1', 'gpt-5-mini', 'claude-sonnet-4-5-20250929', 'gemini/gemini-2.5-flash-lite', 'mistral/mistral-small-latest', 'mistral/mistral-medium-latest', 'gemini/gemini-2.5-pro', 'gemini/gemini-3-pro-preview' or 'llama3.1-70b'",
            "input": "",
            "ctx": {
                "expected": "'gpt-5-chat-latest', 'gpt-5.1', 'gpt-5-mini', 'claude-sonnet-4-5-20250929', 'gemini/gemini-2.5-flash-lite', 'mistral/mistral-small-latest', 'mistral/mistral-medium-latest', 'gemini/gemini-2.5-pro', 'gemini/gemini-3-pro-preview' or 'llama3.1-70b'"
            }
        }
    ]
}

Cause: Invalid or unsupported model_name in model_data. See supported models list above.


400 Bad Request - Missing Question

{
    "data": {},
    "message": "query not provided"
}

Cause: The question field is empty or missing from the request body.


400 Bad Request - Invalid Document IDs

{
    "data": {},
    "message": "Invalid docs selected"
}

Causes:

  • Missing or invalid doc_process_ids.

500 Internal Server Error - Invalid LLM API Key

{
    "data": {},
    "message": "litellm.AuthenticationError: AuthenticationError: OpenAIException - Incorrect API key provided: tyrdfuih**uhf7. You can find your API key at https://platform.openai.com/account/api-keys."
}

Cause: The api_key provided in model_data is invalid or expired. Verify your LLM provider API key.


500 Internal Server Error - General Error

{
    "data": {},
    "message": "Something went wrong"
}

Causes:

  • LLM service temporarily unavailable
  • Server-side processing error

Code Snippets

curl --location 'https://api.k-v.ai/api/agent/k_search' \
--header 'access-key: YOUR_ACCESS_KEY' \
--header 'Content-Type: application/json' \
--data '{
   "doc_process_ids": ["264dfa262b748d15ccbeaada89430c68"],
   "question": "what are the parties involved?",
   "context": "concise",
   "model_data": {
       "model_name": "gpt-5.1",
       "api_key": ""
   }
}'
import requests
import json

url = "https://api.k-v.ai/api/agent/k_search"

payload = json.dumps({
  "doc_process_ids": [
    "264dfa262b748d15ccbeaada89430c68"
  ],
  "question": "what are the parties involved?",
  "context": "concise",
  "model_data": {
    "model_name": "gpt-5.1",
    "api_key": ""
  }
})
headers = {
  'access-key': 'YOUR_ACCESS_KEY',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
const axios = require('axios');
let data = JSON.stringify({
  "doc_process_ids": [
    "264dfa262b748d15ccbeaada89430c68"
  ],
  "question": "what are the parties involved?",
  "context": "concise",
  "model_data": {
    "model_name": "gpt-5.1",
    "api_key": ""
  }
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://api.k-v.ai/api/agent/k_search',
  headers: { 
    'access-key': 'YOUR_ACCESS_KEY', 
    'Content-Type': 'application/json'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

Important Notes

  • Document Processing: Only search documents with status: "processed" from List Documents API
  • Question Quality: More specific questions yield better answers

Next Steps

After using Knowledge Search:

  • Refine Questions: Iterate on question phrasing for better results
  • Analyze Sources: Review source scores and citations for accuracy
  • Build Applications: Integrate into chatbots, Q&A systems, or workflows

Need Help? Contact support at support@k-v.ai

On this page