7bfb9946
tangwang
向量化模块
|
1
2
|
"""
Embeddings module.
|
be52af70
tangwang
first commit
|
3
|
|
7bfb9946
tangwang
向量化模块
|
4
|
Important: keep package import lightweight.
|
be52af70
tangwang
first commit
|
5
|
|
7bfb9946
tangwang
向量化模块
|
6
|
Some callers do:
|
950a640e
tangwang
embeddings
|
7
8
|
- `from embeddings import TextEmbeddingEncoder`
- `from embeddings import BgeEncoder` (deprecated alias)
|
7bfb9946
tangwang
向量化模块
|
9
10
11
12
13
14
15
16
|
- `from embeddings import CLIPImageEncoder`
But the underlying implementations may import heavy optional deps (Pillow, torch, etc).
To avoid importing those at package import time (and to allow the embedding service to boot
without importing client code), we provide small lazy factories here.
"""
|
950a640e
tangwang
embeddings
|
17
18
|
class TextEmbeddingEncoder(object):
"""Lazy factory for `embeddings.text_encoder.TextEmbeddingEncoder`."""
|
7bfb9946
tangwang
向量化模块
|
19
20
|
def __new__(cls, *args, **kwargs):
|
950a640e
tangwang
embeddings
|
21
|
from .text_encoder import TextEmbeddingEncoder as _Real
|
7bfb9946
tangwang
向量化模块
|
22
23
24
25
|
return _Real(*args, **kwargs)
|
950a640e
tangwang
embeddings
|
26
27
28
29
|
class BgeEncoder(TextEmbeddingEncoder):
"""Deprecated backward-compatible alias for old class name."""
|
7bfb9946
tangwang
向量化模块
|
30
31
32
33
34
35
36
37
38
|
class CLIPImageEncoder(object):
"""Lazy factory for `embeddings.image_encoder.CLIPImageEncoder`."""
def __new__(cls, *args, **kwargs):
from .image_encoder import CLIPImageEncoder as _Real
return _Real(*args, **kwargs)
|
950a640e
tangwang
embeddings
|
39
|
__all__ = ["TextEmbeddingEncoder", "BgeEncoder", "CLIPImageEncoder"]
|