Blame view

embeddings/protocols.py 1.21 KB
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
          """
          ...
7a013ca7   tangwang   多模态文本向量服务ok
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  
      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.
          """
          ...