Blame view

embeddings/protocols.py 809 Bytes
c10f90fe   tangwang   cnclip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  """
  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,
200fdddf   tangwang   embed norm
20
          normalize_embeddings: bool = True,
c10f90fe   tangwang   cnclip
21
22
23
24
25
26
27
28
      ) -> List[Optional[np.ndarray]]:
          """
          Encode a list of image URLs to vectors.
  
          Returns:
              List of vectors (or None for failed items), same length as urls.
          """
          ...