Skip to content

Commit f4f37b6

Browse files
committed
Include date and tag information from frontmatter in the vector store
1 parent a061a9e commit f4f37b6

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

app/indexer.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,18 @@ def build_index_files(sources: List[str]) -> int:
368368
chunks = _iter_chunks(text_norm)
369369
total_chunks += len(chunks)
370370

371-
# Fallback date for undated chunks: file mtime as ISO date.
372-
fallback_entry_date = _dt.datetime.fromtimestamp(mtime).date().isoformat()
371+
# Fallback date for undated chunks: frontmatter date > file mtime.
372+
# PyYAML parses YAML date fields as datetime.date objects; also accept strings.
373+
_fm_date = meta.get("date")
374+
if isinstance(_fm_date, (_dt.date, _dt.datetime)):
375+
fallback_entry_date = _fm_date.date().isoformat() if isinstance(_fm_date, _dt.datetime) else _fm_date.isoformat()
376+
elif isinstance(_fm_date, str) and _fm_date.strip():
377+
try:
378+
fallback_entry_date = _dt.date.fromisoformat(_fm_date.strip()).isoformat()
379+
except ValueError:
380+
fallback_entry_date = _dt.datetime.fromtimestamp(mtime).date().isoformat()
381+
else:
382+
fallback_entry_date = _dt.datetime.fromtimestamp(mtime).date().isoformat()
373383

374384
# mark old for deletion
375385
if prev and "count" in prev:
@@ -418,6 +428,9 @@ def build_index_files(sources: List[str]) -> int:
418428
header_parts.insert(1, f"entities: {entities_txt}")
419429
if effective_date:
420430
header_parts.append(f"date: {effective_date}")
431+
tags_txt = up_meta.get("tags") or ""
432+
if tags_txt:
433+
header_parts.append(f"tags: {tags_txt}")
421434
header = "[" + "] [".join(header_parts) + "]"
422435
text_with_meta = f"{header}\n\n{c}"
423436
to_upsert.append((cid, up_meta, text_with_meta))

0 commit comments

Comments
 (0)