• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

neuml / txtai / 3875424846

pending completion
3875424846

push

github

davidmezzetti
Add language-modeling task to HFTrainer, closes #403

36 of 36 new or added lines in 4 files covered. (100.0%)

4501 of 4505 relevant lines covered (99.91%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/python/txtai/ann/factory.py
1
"""
2
Factory module
3
"""
4

5
from ..util import Resolver
1✔
6

7
from .annoy import Annoy
1✔
8
from .faiss import Faiss
1✔
9
from .hnsw import HNSW
1✔
10

11

12
class ANNFactory:
1✔
13
    """
14
    Methods to create ANN indexes.
15
    """
16

17
    @staticmethod
1✔
18
    def create(config):
19
        """
20
        Create an ANN.
21

22
        Args:
23
            config: index configuration parameters
24

25
        Returns:
26
            ANN
27
        """
28

29
        # ANN instance
30
        ann = None
1✔
31
        backend = config.get("backend", "faiss")
1✔
32

33
        # Create ANN instance
34
        if backend == "annoy":
1✔
35
            ann = Annoy(config)
1✔
36
        elif backend == "faiss":
1✔
37
            ann = Faiss(config)
1✔
38
        elif backend == "hnsw":
1✔
39
            ann = HNSW(config)
1✔
40
        else:
41
            ann = ANNFactory.resolve(backend, config)
1✔
42

43
        # Store config back
44
        config["backend"] = backend
1✔
45

46
        return ann
1✔
47

48
    @staticmethod
1✔
49
    def resolve(backend, config):
50
        """
51
        Attempt to resolve a custom backend.
52

53
        Args:
54
            backend: backend class
55
            config: index configuration parameters
56

57
        Returns:
58
            ANN
59
        """
60

61
        try:
1✔
62
            return Resolver()(backend)(config)
1✔
63
        except Exception as e:
1✔
64
            raise ImportError(f"Unable to resolve ann backend: '{backend}'") from e
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc