protocols.py
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Protocols for embedding backends (structural typing, no inheritance required).
Used by the embedding service so that any backend (ClipAsServiceImageEncoder,
ClipImageModel, etc.) can be used as long as it implements the same interface.
"""
from typing import List, Optional, Protocol
import numpy as np
class ImageEncoderProtocol(Protocol):
"""Contract for image encoders used by the embedding service /embed/image endpoint."""
def encode_image_urls(
self,
urls: List[str],
batch_size: Optional[int] = None,
normalize_embeddings: bool = True,
) -> List[np.ndarray]:
"""
Encode a list of image URLs to vectors.
Returns:
List of vectors, same length as urls. Invalid inputs should raise instead
of returning partial None placeholders.
"""
...
def encode_clip_texts(
self,
texts: List[str],
batch_size: Optional[int] = None,
normalize_embeddings: bool = True,
) -> List[np.ndarray]:
"""
Encode natural-language strings with the CLIP/CN-CLIP text tower (same space as images).
Returns:
List of vectors, same length as texts.
"""
...