Skip to content

Knowledge Base

PantheraNestah edited this page Nov 5, 2026 · 1 revision

Knowledge Base

The system answers only from six public documents. They live in data/raw/; their extracted text is in data/knowledge_base/nutrition_knowledge_base.json (810 chunks); the vector store built from it is app/chroma_storage/ (not in git).

Documents

Document Publisher Year Domain Kenya-specific Chunks
Kenya Nutrition Action Plan 2018-2022 Kenya Ministry of Health 2018 nutrition yes 284
Kenya Food Composition Tables FAO / Kenya MoH 2018 nutrition yes 209
National Guidelines for Healthy Diets and Physical Activity Kenya Ministry of Health 2017 nutrition yes 146
General Principles of Food Hygiene FAO/WHO Codex 2023 food_safety no 94
Kenya Nutrient Profile Model (KNPM) Kenya Ministry of Health 2025 nutrition yes 63
WHO healthy diet fact sheet WHO 2024 nutrition no 14

By domain: 716 chunks nutrition, 94 chunks food_safety. Authority, year, domain and Kenya relevance are set per document in data/scripts/source_metadata.py.

Pipeline

data/raw/*.pdf
  -> ingest_documents.py   extract text (PyMuPDF), clean, split into sentence-based chunks of 100-220 words
  -> data/knowledge_base/nutrition_knowledge_base.json
  -> build_vector_store.py embed each chunk (all-mpnet-base-v2), store in ChromaDB collection "nutrition_kb"
  -> app/chroma_storage/

Each chunk record has chunk_id (<pdf file name without extension>_<n>), text, source_document, authority, year, domain and kenya_relevance. These fields are stored in ChromaDB as metadata (kenya_relevance as a string).

Rebuild the vector store from the JSON

You do not need the PDFs for this. Run python data/scripts/build_vector_store.py (Getting Started). Chunks whose text is unchanged are not re-embedded, so re-running only embeds new or edited chunks; use --reset after a re-ingest so chunks that no longer exist do not linger. Then restart the server: the BM25 index is built at startup and never refreshed.

The collection keeps Chroma's default (L2) distance setting, which the retriever was written against; the script deliberately does not change it.

Re-ingest or add a document

  1. Put the PDF in data/raw/.
  2. Add an entry to SOURCE_METADATA in data/scripts/source_metadata.py (authority, year, domain, Kenya relevance).
  3. Run python data/scripts/ingest_documents.py from the repository root. It uses NLTK sentence tokenisation, so the NLTK punkt data must be installed (python -m nltk.downloader punkt punkt_tab); without it the script falls back to a crude split.
  4. Rebuild the vector store with --reset, then restart the server.

Re-ingesting rewrites the JSON and changes chunk boundaries and IDs, which makes the committed evaluation test set (Evaluation) refer to chunks that no longer match.

Known limits

  • Numbers are stripped. clean_text() removes standalone integers (to drop page numbers), which also damages tables of values. The food-composition document is mostly tables, so numeric answers from it are unreliable.
  • English only, and only the nutrition and food_safety domains exist.
  • Coverage is small. Questions outside these six documents get an "not enough information" answer, by design.
  • Licences. The documents are public, but redistribution terms differ. The FAO/WHO text carries a Creative Commons non-commercial notice. Check each publisher's terms before redistributing PDFs or extracted text (Known Issues and Limitations).

Clone this wiki locally