liveBook · Manning

Knowledge base

As explained in Build Python Web Apps with Streamlit

A knowledge base is an organized collection of information that a system can consult to answer questions about a defined subject.

A customer-support chatbot needs reliable information about the company it represents. A knowledge base supplies that information: here, it is a folder of text articles about products and business practices. The chatbot uses it to answer relevant customer questions, while order tracking and cancellation are separate actions. section 10.1.1 section 10.5.2

A question about fountain pens

An article about fountain-pen maintenance advises cleaning the nib with warm water, using high-quality ink, and storing pens upright. A customer asking how to care for a pen needs that article’s relevant advice, not every support article. section 10.5.2 section 10.5.1

Sending the entire knowledge base with every question can overload the model and raise token costs. Retrieval-augmented generation (RAG) instead finds the relevant parts, adds them to the question’s context, and asks the language model to answer. Finding the right parts is the main challenge. section 10.5.1

To make the articles searchable:

  • Load the text files and split them into overlapping chunks. section 10.5.2
  • Store the chunks and their embeddings in a Pinecone index, then use similarity search to retrieve chunks for a customer question. section 10.5.2
  • Place retrieved excerpts in the chatbot’s instructions. If they do not support a confident answer, direct the customer to a human representative. section 10.5.2
@staticmethod
def augment_node(state: AgentState):
  docs = state["retrieved_docs"]
  docs_content_list = [doc.page_content for doc in docs]
  content = "\n".join(docs_content_list)
  new_text = SYS_MSG_AUGMENTATION.replace("{docs_content}", content)
  return {"sys_msg_text": BASE_SYS_MSG + "\n\n" + new_text}

The augmentation step joins retrieved document contents and adds them to the system message before the chatbot answers. section 10.5.2

How Build Python Web Apps with Streamlit covers it

How deep it goes
Works through article ingestion, chunking, retrieval, and prompt augmentation, but treats embedding internals only conceptually.
Examples
Uses product descriptions and fountain-pen maintenance articles as customer-support information.
What it assumes
Introduces embeddings and vector databases conceptually before using Python code, API keys, and text articles.
What you can do after
Apply it via Pinecone and LangChain to retrieve support-article excerpts for chatbot answers.
How it connects
Connects the knowledge base to retrieval-augmented generation, embeddings, vector databases, similarity search, and human escalation.

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 Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.