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

neuml / txtai / 11333404567

14 Oct 2024 06:53PM UTC coverage: 99.947%. Remained the same
11333404567

push

github

davidmezzetti
Bump version

1 of 1 new or added line in 1 file covered. (100.0%)

7542 of 7546 relevant lines covered (99.95%)

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
from .numpy import NumPy
1✔
11
from .pgvector import PGVector
1✔
12
from .sqlite import SQLite
1✔
13
from .torch import Torch
1✔
14

15

16
class ANNFactory:
1✔
17
    """
18
    Methods to create ANN indexes.
19
    """
20

21
    @staticmethod
1✔
22
    def create(config):
1✔
23
        """
24
        Create an ANN.
25

26
        Args:
27
            config: index configuration parameters
28

29
        Returns:
30
            ANN
31
        """
32

33
        # ANN instance
34
        ann = None
1✔
35
        backend = config.get("backend", "faiss")
1✔
36

37
        # Create ANN instance
38
        if backend == "annoy":
1✔
39
            ann = Annoy(config)
1✔
40
        elif backend == "faiss":
1✔
41
            ann = Faiss(config)
1✔
42
        elif backend == "hnsw":
1✔
43
            ann = HNSW(config)
1✔
44
        elif backend == "numpy":
1✔
45
            ann = NumPy(config)
1✔
46
        elif backend == "pgvector":
1✔
47
            ann = PGVector(config)
1✔
48
        elif backend == "sqlite":
1✔
49
            ann = SQLite(config)
1✔
50
        elif backend == "torch":
1✔
51
            ann = Torch(config)
1✔
52
        else:
53
            ann = ANNFactory.resolve(backend, config)
1✔
54

55
        # Store config back
56
        config["backend"] = backend
1✔
57

58
        return ann
1✔
59

60
    @staticmethod
1✔
61
    def resolve(backend, config):
1✔
62
        """
63
        Attempt to resolve a custom backend.
64

65
        Args:
66
            backend: backend class
67
            config: index configuration parameters
68

69
        Returns:
70
            ANN
71
        """
72

73
        try:
1✔
74
            return Resolver()(backend)(config)
1✔
75
        except Exception as e:
1✔
76
            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