66f7db40b0
Three FastAPI backends comparing PostgreSQL/pgvector and Oracle 26ai for semantic image search using CLIP embeddings: Python-side embedding for both databases, plus Oracle in-database embedding via VECTOR_EMBEDDING(CLIP_TXT). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
18 lines
443 B
Python
18 lines
443 B
Python
from sentence_transformers import SentenceTransformer
|
|
from PIL import Image
|
|
|
|
_model = None
|
|
|
|
def _get_model():
|
|
global _model
|
|
if _model is None:
|
|
_model = SentenceTransformer("clip-ViT-B-32")
|
|
return _model
|
|
|
|
def embed_image(path: str) -> list[float]:
|
|
img = Image.open(path).convert("RGB")
|
|
return _get_model().encode(img).tolist()
|
|
|
|
def embed_text(text: str) -> list[float]:
|
|
return _get_model().encode(text).tolist()
|