Blame view

embeddings/protocols.py 860 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,
af03fdef   tangwang   embedding模块代码整理
21
      ) -> List[np.ndarray]:
c10f90fe   tangwang   cnclip
22
23
24
25
          """
          Encode a list of image URLs to vectors.
  
          Returns:
af03fdef   tangwang   embedding模块代码整理
26
27
              List of vectors, same length as urls. Invalid inputs should raise instead
              of returning partial None placeholders.
c10f90fe   tangwang   cnclip
28
29
          """
          ...