liveBook · Manning

Knowledge base

As explained in Build AI-Enhanced Web Apps

A knowledge base is an organized collection of information representing questions, answers, facts, or other domain knowledge.

A knowledge base organizes domain information so users or AI assistants can retrieve answers from questions, documents, facts, or other structured content. In web applications, it commonly becomes the source of grounded conversational responses. section 11.1 section 11.4

A production knowledge-base application combines authenticated access, document management, vector representations, search, and a conversational interface. Users can create separate collections, upload PDF or DOCX files, and query the selected collection through an AI assistant. section 11.1 section 11.1.1 section 11.4

A typical retrieval workflow proceeds as follows:

  • Store questions, answers, or parsed document content together with their embeddings. section 5.4.3 section 11.1.1
  • Embed each user query with the same model used for stored content. section 5.4.3
  • Compare the query embedding with stored embeddings and select the closest result or several high-scoring results. section 5.4.3
  • Return the matched answer directly or provide retrieved context to an AI model for formatted conversational output. section 5.4.3 section 11.4

IT support knowledge base

Store questions such as “How do I reset my password?” with their answers. For “I forgot my password,” generate a query embedding, compare it using cosine similarity, and return the matching password-reset guidance. section 5.4.3

Listing 5.9 Converting text to embeddings
const embeddingDB = {};    #1
const questions = [
  "How do I reset my password?",
  "What should I do if my computer won't start?",
];    #2

const answers = [   #3
  "To reset your password, go to the login page and click 
'Forgot Password'. Follow the instructions to reset 
your password.",
  "If your computer won't start, check the power cable, try 
restarting it, and if the issue persists, contact support.",
];

for (let i = 0; i < questions.length; i++) {
  const { embedding } = await embed({
    model: google.textEmbeddingModel("text-embedding-004"),
    value: questions[i],
  });
  embeddingDB[questions[i]] = embedding;    #4
}

The listing demonstrates a JavaScript embedding database built from question-and-answer pairs, using Google's text-embedding-004 model. section 5.4.3

How Build AI-Enhanced Web Apps covers it

How deep it goes
Explains document workflows and embedding-based retrieval, including query encoding and cosine similarity, while deferring deeper vector-store implementation.
Examples
Uses IT support questions, interview best practices, PDF and DOCX uploads, multi-tenant collections, and conversational corporate knowledge bases.
What it assumes
Assumes JavaScript application development and introduces embeddings, similarity search, document uploads, vector stores, and retrievers through implementation.
What you can do after
Build it from scratch as a JavaScript retrieval workflow or operate it as a secure multi-knowledge-base chat application.
How it connects
Connects embeddings, similarity search, document parsing, vector search, retrieval-augmented generation, authentication, and conversational AI.

Also explained in

Compare how 10 books explain knowledge base →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.