step B.6 complete: POST /api/v1/storage/vectors/embed endpoint

This commit is contained in:
2026-03-05 00:07:06 +01:00
parent 6d9a16e513
commit cc603aba06
2 changed files with 25 additions and 2 deletions

View File

@@ -205,7 +205,7 @@ Tools must use **camelCase** field names (Drizzle maps them to snake_case intern
- **Outcome:** Clean final frame. No more action descriptors in the protocol.
### Step B.6 — Add `/vectors/embed` endpoint
- [ ] Add to `app/api/routes/vectors.py`:
- [x] Add to `app/api/routes/vectors.py`:
- `POST /api/v1/storage/vectors/embed`:
- Request: `{ text: str }`
- Response: `{ vector: list[float] }` (1536-dim from `text-embedding-3-small`)

View File

@@ -1,4 +1,4 @@
"""Vectors routes: upsert, search, and delete cloud vector store entries."""
"""Vectors routes: upsert, search, delete cloud vector store entries, and embed text."""
from __future__ import annotations
@@ -6,6 +6,7 @@ from fastapi import APIRouter, Depends
from pydantic import BaseModel
from app.api.deps import get_current_user
from app.core.llm import embed
from app.schemas import (
UserProfile,
VectorSearchRequest,
@@ -24,6 +25,14 @@ class _VectorDeleteRequest(BaseModel):
ids: list[str]
class _EmbedRequest(BaseModel):
text: str
class _EmbedResponse(BaseModel):
vector: list[float]
@router.post("/vectors/upsert", response_model=dict)
async def upsert_vectors(
body: VectorUpsertRequest,
@@ -54,3 +63,17 @@ async def delete_vectors(
"""Delete vectors by ID, scoped to the authenticated user."""
await _vector_store.delete(current_user.id, body.ids)
return {"ok": True}
@router.post("/vectors/embed", response_model=_EmbedResponse)
async def embed_text(
body: _EmbedRequest,
current_user: UserProfile = Depends(get_current_user),
) -> _EmbedResponse:
"""Generate a 1536-dim embedding vector for the given text.
Uses ``text-embedding-3-small`` via OpenAI. Auth required (JWT).
Used by backend tools (note_agent) and Electron (vectordb.ts) alike.
"""
vector = await embed(body.text)
return _EmbedResponse(vector=vector)