2.4 KiB
2.4 KiB
Quickstart: Enhanced Embedding with Image Parsing and Metadata
Branch: 002-image-aware-embedding | Date: 2026-04-03
Prerequisites
- Docker Compose running (PostgreSQL + pgvector)
- OpenAI API key set in
backend/src/main/resources/application.propertiesor as env varOPENAI_API_KEY - Java 25 + Maven on PATH
New Configuration
Add to backend/src/main/resources/application.properties:
# Figure storage
app.figure-storage.base-path=./uploads
app.figure-storage.min-image-size-px=100
The uploads/figures/ directory is created automatically on first use. Add it to .gitignore.
Database Migration
Two new Flyway migrations run automatically on startup:
V4__document_hierarchy.sql— addschapterandsectiontablesV5__figures_and_refs.sql— addsfigureandchunk_figure_reftables
No manual DB setup needed.
Re-embedding Existing Books
Books embedded by feature 001 (text-only) remain functional for text queries. To add image support, trigger a re-embed:
curl -X POST http://localhost:8080/api/v1/books/{bookId}/reembed \
-u admin:password
The book transitions to PROCESSING, old chunks and figures are deleted, and the new
image-aware pipeline runs. Status can be polled via GET /api/v1/books.
Verifying Image Extraction
- Upload a PDF with diagrams:
POST /api/v1/books/upload - Wait for
status: "READY"viaGET /api/v1/books - List figures:
GET /api/v1/books/{id}/figures— should return at least one entry per image page - Ask a diagram-specific question in chat — response
sourcesshould include atype: "FIGURE"entry
Frontend: Rendering Inline Figures
The assistant message content field will contain figure references in the format
[Fig. 12-4, p.184]. The frontend should:
- Parse
[Fig. X, p.N]patterns in assistant message text - Look up the matching entry in
sourceswheretype === "FIGURE" - Render the figure inline using the
imageUrlfield
Running Tests
cd backend
mvn test
Key new test classes:
FigureExtractionServiceTest— unit tests for image extraction and classificationNeurosurgeryRetrieverTest— unit tests for dual-search merge and deduplicationBookEmbeddingServiceIntegrationTest— integration test: upload PDF with known figures, verify figures appear inGET /api/v1/books/{id}/figures