AI From Zero · AI for Developers

Working With Documents and Knowledge Bases

Learn how developers prepare documents, build knowledge bases, retrieve relevant information, and connect document knowledge to AI applications.

Estimated learning time: 55 minutes

What You'll Learn

  • Understand what document and knowledge base systems are
  • Learn how documents are ingested and prepared for AI applications
  • Understand document extraction, cleaning, normalization, and chunking
  • Learn why metadata is important for document retrieval
  • Understand embeddings, vector databases, and retrieval
  • Learn how documents are connected to RAG systems
  • Understand document permissions and access control
  • Learn how to handle scanned documents, OCR, duplicates, and outdated content
  • Understand document freshness, versioning, monitoring, and evaluation
  • Design a basic AI knowledge base architecture

1. Introduction

Many useful AI applications need access to information that is not contained in the AI model itself. Company policies, product manuals, technical documentation, training materials, contracts, support articles, and internal procedures may all contain information that an AI application needs to use.

Documents and knowledge bases provide a way to organize this information so that an AI application can retrieve relevant content when needed.

2. What Is a Document System?

A document system stores and manages information contained in files or other sources. Documents may include PDFs, word-processing files, spreadsheets, presentations, web pages, text files, scanned documents, or records extracted from business systems.

The original document is normally treated as source information. AI processing creates additional representations of that information without replacing the original source.

3. What Is a Knowledge Base?

A knowledge base is an organized collection of information that can be searched or retrieved to answer questions or support business processes.

A knowledge base can contain documents, articles, database records, frequently asked questions, product information, policies, or other approved sources.

An AI knowledge base usually combines traditional data storage with search, retrieval, and AI generation.

4. Document Ingestion

Document ingestion is the process of bringing information from source documents into a system that can process and retrieve it.

A typical ingestion process may include:

  • Receiving the source document
  • Identifying the document type
  • Extracting the content
  • Cleaning and normalizing the content
  • Splitting the content into useful sections
  • Adding metadata
  • Generating embeddings when semantic retrieval is required
  • Storing the processed information

5. Supported Document Formats

Different applications may work with different document formats. Common examples include PDF, DOCX, XLSX, PPTX, HTML, CSV, TXT, and structured data formats.

The format affects how information can be extracted. A text-based PDF is different from a scanned PDF. A spreadsheet requires different processing from a word-processing document.

6. Extracting Document Content

Extraction converts information from a document into data that the application can process.

Extraction should preserve useful structure where possible. Headings, paragraphs, tables, lists, page information, and other meaningful elements may be important during retrieval.

Poor extraction can create poor retrieval even when the AI model itself is capable of producing good answers.

7. Cleaning and Normalization

Extracted document content may contain unwanted formatting, repeated headers, broken characters, unnecessary whitespace, navigation elements, or other noise.

Cleaning and normalization improve the quality of the information stored in the knowledge base.

However, cleaning should not remove information that may be important for understanding the original source.

8. Chunking Documents

Large documents are normally divided into smaller sections called chunks.

Chunking makes retrieval more precise because a system can retrieve relevant sections instead of sending an entire large document to the AI model.

Good chunk boundaries often follow meaningful structures such as headings, paragraphs, sections, or related groups of information.

9. Choosing Chunk Size

Very small chunks may lose important context. Very large chunks may contain unrelated information and consume more context space.

The appropriate chunk size depends on the document type, retrieval method, question types, and application requirements.

Chunking should therefore be treated as an engineering decision rather than a universal fixed value.

10. Metadata

Metadata describes information about a document or document section.

Useful metadata may include:

  • Document identifier
  • Document title
  • Source
  • Author or department
  • Creation date
  • Last updated date
  • Version
  • Page number
  • Document category
  • Access permissions

Metadata can help with filtering, source identification, version management, and access control.

11. Embeddings

After documents are prepared and divided into chunks, embeddings can be generated for those chunks.

An embedding represents information as a numerical vector. Similar meanings can produce vectors that are mathematically closer under an appropriate similarity measure.

This allows semantic retrieval rather than relying only on exact keyword matching.

12. Vector Databases

Vector databases can store embeddings and support similarity searches.

A typical knowledge base may store the original document separately while storing document chunks, embeddings, and metadata in systems designed for retrieval.

The vector database therefore supports retrieval, but it does not necessarily replace the original source repository.

13. Retrieval

When a user asks a question, the application can convert the question into a representation suitable for search and retrieve relevant document sections.

Retrieval may use semantic similarity, keyword search, metadata filters, or a combination of several methods.

The quality of retrieval has a direct effect on the quality of the final AI response.

14. Connecting Documents to RAG

Retrieval-Augmented Generation, or RAG, combines information retrieval with AI generation.

A simplified workflow is:

  1. User submits a question
  2. Application processes the question
  3. Relevant knowledge base content is retrieved
  4. Retrieved content is added to the model context
  5. The AI model generates a response
  6. The application validates and presents the response

The model uses retrieved information as context rather than relying only on information learned during model training.

15. Source Citations

Knowledge base applications can provide source information along with an answer. This may include document titles, page numbers, URLs, document identifiers, or other references.

Source citations help users verify important information and make the application more transparent.

16. Document Freshness

Knowledge bases can become inaccurate when source documents change but the processed knowledge is not updated.

A production system should therefore have a process for detecting updated documents and refreshing the associated chunks, metadata, embeddings, and indexes.

17. Document Versioning

Documents may have multiple versions. A knowledge base should distinguish current information from historical versions when that distinction matters.

For example, an old employee policy should not normally be retrieved as the current policy when a newer approved version exists.

18. Duplicate and Outdated Content

Duplicate documents can cause the same information to appear repeatedly in retrieval results.

Outdated documents can be even more problematic because they may contain information that conflicts with current policies or procedures.

Knowledge base maintenance should identify duplicates, obsolete content, and conflicting versions.

19. OCR and Scanned Documents

Some PDFs and images contain scanned pages rather than machine-readable text.

Optical Character Recognition, or OCR, can convert text visible in scanned documents into machine-readable content.

OCR results should be checked because recognition errors can change important words, numbers, names, or dates.

20. Structured and Unstructured Documents

Unstructured documents such as reports and policy documents mainly contain natural language and varying layouts.

Structured sources such as spreadsheets, databases, and tables have more predictable organization.

Different source types may require different ingestion and retrieval strategies.

21. Access Control

Retrieval must respect application permissions.

A document being present in a knowledge base does not mean every user should be able to retrieve it.

Authentication identifies the user, while authorization determines which information that user is allowed to access.

22. Document-Level and Metadata-Level Filtering

Access restrictions can be represented through document metadata and application-level rules.

For example, documents may contain department, classification, region, or permission information. The application can use these attributes to restrict retrieval.

Security should be enforced by the application rather than relying only on instructions given to the AI model.

23. Security of Retrieved Content

Retrieved documents may contain malicious or misleading instructions intended to influence the AI model.

This is one form of prompt injection through external content.

Retrieved information should therefore be treated as data rather than automatically trusted instructions. Application controls should determine what actions the AI system is permitted to perform.

24. Privacy

Knowledge bases may contain confidential business information or personal information.

Developers should collect only information required for the application, restrict access appropriately, protect stored data, and consider how document content is transmitted to AI services.

25. Knowledge Base Architecture

A basic architecture may contain the following components:

  • Source document repository
  • Document ingestion service
  • Text extraction and cleaning process
  • Chunking process
  • Metadata store
  • Embedding service
  • Vector database
  • Search and retrieval layer
  • AI model
  • Application backend
  • User interface

These components can be implemented using different technologies depending on application requirements.

26. Example: HR Policy Knowledge Base

Imagine a company builds an AI assistant for employee questions.

The source documents include approved HR policies, leave rules, benefits information, and workplace procedures.

The documents are extracted, cleaned, divided into sections, tagged with metadata, embedded, and indexed.

When an employee asks a question, the application retrieves relevant approved policy sections and provides them to the AI model as context.

The response can include the source policy so the employee can verify the information.

27. Example: Product Support Knowledge Base

A product company may create a knowledge base from manuals, troubleshooting guides, release documentation, and support articles.

The retrieval system can use product model metadata so that information for one product is not incorrectly retrieved for another product.

28. Example: Course Content Knowledge Base

An educational platform can organize lessons, explanations, exercises, and reference material into a searchable knowledge base.

An AI course assistant can retrieve relevant course sections before answering learner questions.

29. Monitoring a Knowledge Base

A production knowledge base should be monitored for both technical and information-quality problems.

Useful measurements may include retrieval latency, retrieval failures, empty results, frequently retrieved documents, outdated content, user feedback, and answer quality.

30. Evaluating Retrieval Quality

A system should be tested using representative questions.

Evaluation can examine whether the correct documents are retrieved, whether irrelevant documents appear, whether important information is missing, and whether the final answer is supported by the retrieved sources.

31. Common Beginner Mistakes

  • Uploading documents without checking extraction quality
  • Using poor chunk boundaries
  • Ignoring metadata
  • Failing to remove obsolete information
  • Ignoring document permissions
  • Assuming vector similarity means factual correctness
  • Sending excessive document content to the AI model
  • Failing to provide source references
  • Trusting retrieved content as instructions
  • Not testing retrieval with realistic questions

32. Limitations

A knowledge base does not automatically make an AI application accurate.

If source documents are incomplete, incorrect, outdated, poorly extracted, or poorly retrieved, the final response may also be unreliable.

Good knowledge base design therefore requires attention to source quality, retrieval quality, application logic, security, and ongoing maintenance.

33. Developer Mental Model

A useful mental model is:

Source documents → ingestion → extraction → cleaning → chunking → metadata → embeddings/indexing → retrieval → AI context → response validation → user

Each stage affects the quality and security of the final application.

34. Where This Module Goes Next

The next lesson focuses on AI application security. After learning how applications connect models, tools, documents, and knowledge bases, developers need to understand how to protect those systems from misuse, unauthorized access, data exposure, and other security risks.

Conclusion

Documents and knowledge bases provide the information layer behind many practical AI applications. Building a reliable system requires much more than uploading files. Developers must extract and prepare content, organize it with useful metadata, retrieve relevant information, respect permissions, manage document versions, evaluate retrieval quality, and safely connect retrieved information to AI generation.

A strong knowledge base gives an AI application useful context while preserving the controls and source information required for reliable software.

Key Takeaways

• A knowledge base organizes information so applications can retrieve useful source content • Document ingestion includes extraction, cleaning, chunking, metadata, and storage • Chunking affects retrieval quality and context • Embeddings enable semantic retrieval • Vector databases support efficient similarity search • RAG connects retrieved document information with AI generation • Source citations improve transparency and verification • Document freshness and versioning are important for reliable answers • OCR is useful for scanned documents but requires quality checking • Retrieval must always respect authentication and authorization • Retrieved content should be treated as data rather than trusted instructions • Knowledge base quality depends on source quality, retrieval quality, security, and maintenance

Try It Yourself

Design a conceptual AI knowledge base for a company HR policy assistant. Define: 1) three types of source documents, 2) the ingestion and extraction process, 3) a suitable chunking approach, 4) at least five metadata fields, 5) how embeddings and vector search would be used, 6) how document versions would be handled, 7) how employee access would be controlled, 8) how source citations would be provided, and 9) two tests for evaluating retrieval quality.

Test Your Knowledge

You've reached the end of this lesson.

Test what you've learned with the Lesson 126 Quiz: Working With Documents and Knowledge Bases.

Take the Quiz
← AI Agents Explained
AI Application Security →
Back to Course