Docs: hardware sizing omits the local knowledge-bank embedder (~3.7 GB resident, ~5.3 GB peak on PDF ingest)

オープン 初心者向け
#7,233 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
docker, helm, python

調査の方向性

まず hindsight-docs/docs/developer/installation.md、knowledge-banks.mdx、configuration.mdx を確認し、メモリに関する説明を報告された測定値および helm/hindsight/values.yaml の4GiのAPI制限と比較してください。ローカルembedderの常駐メモリとピーク時のメモリ要件を記載し、デフォルト設定を使用するデプロイに、より高い上限が必要かどうかを明確にしてください。更新された説明をもとに、読者がコンテナとHelmデプロイのサイズを決められる状態になれば完了です。

索引モデルが issue の本文から書いたものです。

説明

core
Bug Description

The documented memory sizing does not account for the local knowledge-bank embedder, which is the default (HINDSIGHT_API_KB_EMBEDDINGS_PROVIDER=local, EmbeddingGemma 2 in-process) now that knowledge banks are enabled by default.

  • hindsight-docs/docs/developer/installation.md → Hardware lists API — Full image at 1.5 GB minimum / 2 GB recommended ("Idle RSS settles around 0.8–1.0 GB; expect 1.2–1.5 GB under load"), counting the BGE embedder (~130 MB) and the MiniLM cross-encoder (~90 MB).
  • The image table on the same page mentions the knowledge banks' EmbeddingGemma 2 model only as "~1.5 GB" bundled in the image.
  • knowledge-banks.mdx and the HINDSIGHT_API_KB_* rows in configuration.mdx give no memory guidance for the embedder.
  • helm/hindsight/values.yaml defaults the API to a 4Gi memory limit.

Measured on 1.3.1, the model alone is about 3.7 GB resident once loaded, and embedding PDF pages peaks at about 5.3 GB, before counting the rest of the server. A deployment sized from the docs runs out of memory on PDF ingest.

This is not a leak: memory plateaus. The model loads on first knowledge-bank use and stays resident.

Steps to Reproduce
  1. Save the script below as repro.py in an empty directory.
  2. Run it in the stock full image, with no server or database:
docker run --rm -m 8g --network none \
  -e HF_HUB_OFFLINE=1 -e TRANSFORMERS_OFFLINE=1 \
  -v "$PWD":/repro:ro \
  --entrypoint /app/api/.venv/bin/python \
  ghcr.io/vectorize-io/hindsight:1.3.1 /repro/repro.py
  1. Read the RSS printed after the model loads and after each document.

The script calls LocalGemmaEmbedder.embed_documents() with batch_size=4 on three documents of 24 synthetic page images (1187×1536 PNG, 560 image tokens, the PDF page recipe in knowledge/media.py), in rounds of 8 with up to 4 in flight. It takes about 16 minutes on CPU.

repro.py
"""RSS of the local knowledge embedder across batches of PDF-page-sized images, called the way the service
calls it: embed_documents() (asyncio.to_thread), several rounds in flight, batch_size 4, 560 image tokens."""
import asyncio, ctypes, gc, io, random, time
from PIL import Image, ImageDraw
from hindsight_api.knowledge.embedders import EmbedInput, LocalGemmaEmbedder

DOCS, PAGES, ROUND, IN_FLIGHT = 3, 24, 8, 4
T0 = time.time()

def log(label):
    s = dict(l.split(":", 1) for l in open("/proc/self/status") if ":" in l)
    mb = lambda k: int(s[k].split()[0]) // 1024
    print(f"{time.time()-T0:7.1f}s {label:<28} rss={mb('VmRSS'):5d}MB peak={mb('VmHWM'):5d}MB threads={int(s['Threads'])}", flush=True)

def page(seed):
    r = random.Random(seed)
    img = Image.new("RGB", (1187, 1536), "white")
    d = ImageDraw.Draw(img)
    for y in range(40, 1500, 22):
        words = ("".join(r.choice("abcdefghijklmnopqrstuvwxyz") for _ in range(r.randint(2, 9))) for _ in range(16))
        d.text((50, y), " ".join(words), fill="black")
    b = io.BytesIO()
    img.save(b, "PNG")
    return b.getvalue()

emb = LocalGemmaEmbedder("google/embeddinggemma-2", dimensions=None, device=None, batch_size=4, image_tokens=280)

async def ingest(doc):
    items = [EmbedInput(modality="image", data=page(doc * 1000 + p), mime="image/png", image_tokens=560) for p in range(PAGES)]
    sem = asyncio.Semaphore(IN_FLIGHT)
    async def one(chunk):
        async with sem:
            return await emb.embed_documents(chunk)
    await asyncio.gather(*(one(items[i:i + ROUND]) for i in range(0, len(items), ROUND)))

async def main():
    log("start")
    emb.ensure_loaded(); log("model loaded")
    for doc in range(DOCS):
        await ingest(doc); log(f"doc {doc + 1} done ({PAGES} pages)")
        time.sleep(15)
    gc.collect(); log("after gc.collect()")
    ctypes.CDLL("libc.so.6").malloc_trim(0); log("after malloc_trim(0)")

asyncio.run(main())
Expected Behavior

The Hardware table and the Knowledge Banks page state what the default local knowledge embedder needs in memory, so a container or Helm limit can be sized for it. The default Helm limit either fits a deployment that uses the default embedder, or the docs say it must be raised.

Actual Behavior

Isolated run (the steps above), ghcr.io/vectorize-io/hindsight:1.3.1, CPU, torch 2.13.0+cpu, 8 GiB limit:

Point RSS
Process start 128 MB
Model loaded 3,653 MB
After document 1 4,125 MB
After document 2 4,249 MB
After document 3 4,247 MB
After malloc_trim(0) 3,726 MB
Peak (VmHWM) 5,346 MB

In a real deployment of the same image under an 8 GiB container limit:

  • The server idled at about 2.5 GiB until its first PDF. The log then showed Knowledge embedder loaded: google/embeddinggemma-2 on cpu (768 dims), and it has idled at about 6.05 GiB RSS since.
  • Ingesting one 1.3 MB PDF (27 passages) peaked at 7.6 GiB.
  • On 1.3.0, submitting 19 PDFs (14 KB to 12.7 MB) within a few seconds failed 15 of them with MediaError: ... the PDF renderer crashed on this file, and the kernel then OOM-killed hindsight-api (Memory cgroup out of memory, anon-rss 8,123,236 kB). The same files ingested without error one or two at a time.

The memory guard added in https://github.com/hindsightai/hindsight/pull/6735 kills the biggest worker process, so it does not help when the memory is held by the server process itself. That PR's description assumes "a 2–3 GB server"; with the local knowledge embedder loaded the server here is about 6 GiB.

Version

1.3.1 (ghcr.io/vectorize-io/hindsight:1.3.1; the OOM kill was on 1.3.0). Docker on Linux x86_64 (kernel 6.12, 20 CPU threads), Python 3.11.18 as shipped in the image, CPU only.

LLM Provider

Other (not involved: knowledge-bank ingest makes no LLM calls)

主要言語
Python
スター
45.2k
フォーク
5.9k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vectorize-io/hindsight のほかの issue

vectorize-io/hindsight の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。