API Design: REST Endpoints

Overview

The api.py provides a lightweight FastAPI service that serves as the search backend and static file server. It exposes endpoints for semantic search, file retrieval, and health monitoring.

Base URL

http://127.0.0.1:8000

Endpoints

GET /

Description: Serves the main frontend HTML file.

Response: text/html


Description: Performs semantic search on the indexed vault using a natural language query.

Parameters:

ParameterTypeRequiredDescription
qstringYesThe semantic search query (e.g., “sunset at the beach”)
limitintegerNoNumber of results to return (default: 12)

Response:

{
  "results": [
    {
      "id": "vault/IMG-20250514-WA0055.jpg",
      "score": 0.92,
      "metadata": {
        "full_path": "D:\\....\\Local-Semantic-Media-Search\\vault\\IMG-20250514-WA0055.jpg",
        "thumbnail_path": ".cache/thumbnails/abc123.webp",
        "filename": "IMG-20250514-WA0055.jpg",
        "mtime": 1747228800.0,
        "file_type": "image"
      }
    }
  ]
}

Notes:

  • Results are filtered by cosine distance threshold (0.7).
  • The score field is the cosine similarity (1 - distance).

GET /file

Description: Streams the original high-resolution image or video file.

Parameters:

ParameterTypeRequiredDescription
pathstringYesFull absolute path to the image or video file

Response: Binary media stream (image/jpeg, video/mp4, etc.) or 404 Not Found.


GET /health

Description: Health check endpoint for monitoring and readiness probes.

Response:

{
  "status": "ok",
  "device": "cuda"
}

GET /thumbnails/*

Description: Serves pre-computed 300x300 WebP thumbnails for search results.

Mount point: /thumbnails

Local directory: .cache/thumbnails/


CORS Policy

{
  "allow_origins": ["*"],
  "allow_credentials": true,
  "allow_methods": ["*"],
  "allow_headers": ["*"]
}

Warning: This is configured for local use. Do not deploy to production without restricting allow_origins.

Error Handling

Status CodeCondition
404 Not FoundRequested file path does not exist on disk
500 Internal Server ErrorEngine not initialized at /search

Last Updated: 2026-06-17