Files
pablan/backend/tests/embedding_stub.py
T
ProfessorNovaandClaude Opus 5 784b76baf7 Pablan, as it stands
Self-hosted knowledge management for SMEs: a split-screen Markdown editor
whose sections an LLM refines while you write, and RAG question answering
over the documents that result. FastAPI + Postgres/pgvector on the back,
SvelteKit on the front, everything OpenAI-compatible and self-hostable.

Squashed into a single commit; the development history stays local.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CA43ZJda8Rbp2hKXNy8f6b
2026-09-04 09:21:37 +02:00

25 lines
822 B
Python

"""Deterministic fake embeddings for indexing/retrieval tests.
Identical text maps to an identical unit vector (cosine distance 0);
unrelated texts land near-orthogonal. Semantics are exercised by the evals
against the real endpoint — these tests cover the SQL plumbing.
"""
import hashlib
import math
import random
from app.models import EMBEDDING_DIM
def deterministic_embedding(text: str) -> list[float]:
seed = hashlib.sha256(text.encode()).digest()
rng = random.Random(seed)
vector = [rng.uniform(-1.0, 1.0) for _ in range(EMBEDDING_DIM)]
norm = math.sqrt(sum(value * value for value in vector))
return [value / norm for value in vector]
async def fake_embed(texts: list[str], *, role: str = "embedding") -> list[list[float]]:
return [deterministic_embedding(text) for text in texts]