Skip to content

KB API: PATCH support for metadata_json sub-fields #85

@krisoye

Description

@krisoye

Context

The admin dashboard needs to allow editing bibliographic metadata for research papers (authors, venue, DOI, abstract). These fields are stored in metadata_json (a JSON string in ChromaDB), but the current PATCH /source/{source_id} endpoint only supports flat ChromaDB fields (person_entity, credibility_tier, etc.). metadata_json is explicitly blocked from updates.

This is a cross-repo dependency for admin-dashboard EPIC krisoye/admin-dashboard#20.

Design

Option A: Selective metadata_json updates (recommended)

Add a new request field metadata_updates: dict[str, Any] to UpdateMetadataRequest. The handler:

  1. Reads current metadata_json string from ChromaDB
  2. Parses it as JSON
  3. Merges the provided updates (shallow merge)
  4. Re-serializes and stores back
class UpdateMetadataRequest(BaseModel):
    # Existing fields...
    metadata_updates: dict[str, Any] | None = None  # New

Option B: Dedicated endpoint

PATCH /source/{source_id}/metadata-json with a JSON body of key-value pairs to merge.

Validation

  • Whitelist allowed keys per source_type to prevent arbitrary data injection
  • Research papers: authors, venue, venue_tier, doi, abstract, peer_reviewed, citations, publication_year
  • YouTube: video_title (others are auto-populated)

Files to Modify

  • src/kb_server.py — UpdateMetadataRequest model, update_metadata endpoint
  • src/vector_kb.pyupdate_metadata() method to handle metadata_json merges

Acceptance Criteria

  • PATCH endpoint accepts metadata_updates dict
  • Updates are merged into existing metadata_json (not replacing it)
  • Allowed keys validated per source_type
  • Existing flat field updates unaffected
  • Returns updated source after merge

Dependencies

None — standalone KB API enhancement.

Related to krisoye/admin-dashboard#20

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions