🧠 Custom Knowledge Base

✨ WHAT IS A KNOWLEDGE BASE?

A Knowledge Base (KB) is an organized collection of documents and web sources that AI uses as exclusive context to answer your questions. Instead of searching the entire web, the AI focuses only on the content that you have selected.

📁 Organization

Group documents by project or topic

🎯 Precision

Answers based only on your content

💰 Token Savings

Pre-analysis of documents to reduce costs

How it works:

1

Create the Knowledge Base

Assign a name, description and system instructions (e.g. "Act as a legal expert")

2

Upload the documents

TXT (3 tokens), PDF, DOCX or web sources. The system automatically generates a summary for each document

3

Query the KB

The AI uses only the summaries and contents of the KB to respond, ignoring general knowledge

Endpoint: POST neuralaiPublicApi with use_kb: true

javascript
const response = await fetch("https://app.neuralaiweb.com/functions/neuralaiPublicApi", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    api_key: "LA_TUA_CHIAVE_API",

📊 Token Consumption:

  • KB Build - TXT: 3 tokens per document (direct extraction + summary)
  • KB Build - PDF/DOCX: 5-150 tokens per document (AI extraction + summary, based on characters)
  • 🎵 Audio/Video transcription: 10 tokens/minute (audio), 15 tokens/minute (video) - automatic language detection
  • 🔗 YouTube URL: 5 tokens + 1 token/1000 chars (extracted subtitles) or 15 tokens/minute (AI fallback)
  • 🌐 Web scraping: 5 tokens + 1 token/2000 chars (article extraction from URL)
  • KB Query: 15 tokens base, 30 if the context exceeds 40,000 characters (summaries + document content)
  • Savings: Up to 70% compared to sending the full text of each document

💡 Practical example:

10 documents × 5 token:50 token (one-time)
Subsequent query:15-30 token
Without KB (full text):100+ token

🔢 How to calculate tokens for your KB:

Formula: Total tokens = (TXT × 3) + (PDF/DOCX × 5) + (queries × 15)

💡 Queries with context over 40,000 characters (many documents or web sources) cost 30 tokens instead of 15.

Example: KB with 10 TXT + 10 PDF + 50 queries/month

TXT documents (10 × 3):30 token
PDF documents (10 × 5):50 token
Monthly queries:50 × 15 = 750 token
Monthly total:830 token

💡 TXT files cost 60% less than PDF/DOCX!

📏 Processing limits

📄 Maximum file size by type

Text files (TXT/MD/CSV/JSON/HTML)50 MB
PDF, DOCX and images20 MB
Audio30 MB
Video150 MB
Web sources (per site)30 pages · 30,000 characters

🧩 Extraction and per-query context

Text extracted per document30.000
Context with a single document20.000
Context per document (KB with multiple documents)12.000
Context per web source8.000
Rows from linked databasesmax 50
Context over 40,000 characters30 token

✅ Advantages over traditional RAG:

  • No "stuffing": The AI doesn't receive too many confusing text chunks
  • Clean context: Only relevant summaries are sent to the model
  • Consistent answers: The KB has clear system instructions (e.g. "Reply only based on the documents")
  • Predictable costs: You pay once for the analysis, then use the KB unlimitedly

⚙️ docs_only mode:

When you create a KB, you can activate docs_only_mode: true. In this mode:

  • The AI responds only using the KB contents
  • The model's general knowledge is excluded
  • Perfect for technical manuals, business documentation, FAQs

🔌 Connectors for Knowledge Base

Import documents directly from GitHub and Google Drive to enrich your Knowledge Base.

GitHub

  • ✓Import README and documentation from repositories
  • ✓Supports .md, .txt, .json, .yml, .js, .py and others
  • ✓Connect your GitHub account via OAuth
  • ✓5 tokens per imported document

Google Drive

  • ✓Import PDF, DOCX, TXT directly from Drive
  • ✓Automatic summary included (5-10 tokens)
  • ✓Connect your Google account via OAuth
  • ✓drive.file scope: access only to files used

💡 Tip: Use connectors to automatically sync documentation from your repositories and cloud storage. Each imported file is automatically analyzed and summarized to optimize costs for subsequent queries.

🧪 KB Chat - Complete HTML Code

Complete chat interface with Knowledge Base integration, web search toggle, voice input (microphone), TTS playback and intent detection for media generation. Save it as kb-chat.html and open it.

html
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>

📋 How to use:

  1. Copy the code above and save it as kb-chat.html
  2. Also download/copy kb-chat.js from the "Esempio Chat KB Completo"
  3. Replace YOUR_API_KEY_HERE in kb-chat.js with your actual API key
  4. Open kb-chat.html in your browser (both files must be in the same folder)
  5. Enable KB toggle and start chatting with your Knowledge Base!