Documentation
¶
Overview ¶
Package chunkctx builds the deterministic context header that gets prepended to a chunk's text before it is used as either an embedding input (internal/scheduler) or a sparse-search match target (internal/search, internal/store — issue #270).
This package used to live inside internal/scheduler (BuildChunkContextHeader), where only the embedding pipeline could reach it. #270 needs the SAME header logic from internal/search/internal/store, and a search -> scheduler import is not viable (scheduler already depends on internal/search's sibling packages for the collection pipeline), so the pure, side-effect-free header builder was extracted here. This move changed nothing about the builder's behaviour — see chunkctx_test.go's golden table, which pins the exact output for representative documents and must keep producing byte-identical strings.
Index ¶
Constants ¶
const ( RecipeTP = model.ChunkSparseCtxV1TP RecipeFull = model.ChunkSparseCtxV1Full )
Recipe 이름. model 패키지의 model.ChunkSparseCtxV1TP/V1Full 과 값이 같다 — model.SearchTuning.ChunkSparseCtxVersion 이 그대로 여기 Recipe 인자가 된다. 상수를 model 에 둔 이유는 model.ChunkSparseCtxV1TP 의 doc comment 참고(이 패키지가 이미 model 을 임포트해서 반대 방향은 순환이 된다).
Variables ¶
This section is empty.
Functions ¶
func BuildChunkContextHeader ¶
BuildChunkContextHeader 는 문서 메타데이터로부터 청크 임베딩 입력 앞에 붙일 문맥 헤더를 결정론적으로 만든다. 같은 문서에 대해 항상 같은 문자열을 돌려주므로(시계·맵 순회 순서에 의존하지 않는다) 재임베딩 결과가 흔들리지 않는다.
형식: "[메일] 2026-09-21(일) · 제목: ... · 보낸사람: ... · 받는사람: ..."
왜 필요한가: 문서 임베딩은 title+content 를 쓰지만 청크 임베딩은 청크 본문만 썼다. 그래서 문서 두 번째 이후 청크는 "누가·언제·무슨 제목" 이라는, 메일· 문자·통화 검색에서 가장 결정적인 단서를 잃은 채로 벡터가 만들어졌다.
개인정보 취급: 전화번호(metadata["number"])는 절대 넣지 않는다. 사람 식별은 이름/표시명(contact_name, display_name, From/To 헤더)이 있을 때만 하고, 값이 [REDACTED] 이거나 숫자·기호뿐이면(= 이름이 아니라 번호) 버린다.
반환값이 빈 문자열이면 붙일 문맥이 하나도 없다는 뜻이므로 호출 측은 청크 본문만 임베딩하면 된다.
func BuildSparseText ¶
BuildSparseText 는 #270 phase B 의 청크 희소(FTS/bigm) 매칭 대상 텍스트를 만든다. recipe 에 따라 헤더 구성만 달라지고, 헤더 뒤에는 항상 청크 본문을 "\n\n" 으로 이어 붙인다 — plainto_tsquery 는 토큰을 AND 로 묶으므로, 이름이 헤더에·본문 단어가 청크에 있는 질의가 한 tsvector 에서 만나야 하기 때문이다(마이그레이션 040 의 sparse_tsv 컬럼 주석 참고).
- RecipeTP: 제목+참여자만(날짜·소스 라벨 없음). 소스 라벨("메일", "통화")이 그 단어를 포함한 질의에서 오탐을 키울 수 있어 분리한다.
- RecipeFull: BuildChunkContextHeader 와 완전히 같다(임베딩 헤더 재사용).
두 번째 반환값이 false 면 알 수 없는 recipe 다 — 호출자(백필 워커, 조회 레인)는 그 행을 건너뛰어야 한다.
반환값은 매칭 전용이다 — SearchResult.Content 나 인용·support_spans· synthesis 프롬프트로는 절대 흘리지 않는다(호출자 책임 — 이 함수는 저장되는 값이 어디로 가는지 모른다).
Types ¶
This section is empty.