Skip to content

Commit

Permalink
Cleanup vectors package, closes #802
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmezzetti committed Oct 18, 2024
1 parent 1ca51e5 commit 79675f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
9 changes: 1 addition & 8 deletions src/python/txtai/vectors/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .huggingface import HFVectors
from .litellm import LiteLLM
from .llama import LlamaCpp
from .words import WordVectors, WORDS
from .words import WordVectors


class VectorsFactory:
Expand Down Expand Up @@ -47,13 +47,6 @@ def create(config, scoring=None, models=None):

# Word vectors
if method == "words":
if not WORDS:
# Raise error if trying to create Word Vectors without vectors extra
raise ImportError(
'Word vector models are not available - install "vectors" extra to enable. Otherwise, specify '
+ 'method="transformers" to use transformer backed models'
)

return WordVectors(config, scoring, models)

# Transformers vectors
Expand Down
5 changes: 3 additions & 2 deletions src/python/txtai/vectors/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ def ismodel(path):
return False

def __init__(self, config, scoring, models):
super().__init__(config, scoring, models)

# Check before parent constructor since it calls loadmodel
if not LITELLM:
raise ImportError('LiteLLM is not available - install "vectors" extra to enable')

super().__init__(config, scoring, models)

def loadmodel(self, path):
return None

Expand Down
11 changes: 11 additions & 0 deletions src/python/txtai/vectors/words.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ class WordVectors(Vectors):
Builds vectors using weighted word embeddings.
"""

def __init__(self, config, scoring, models):
# Check before parent constructor since it calls loadmodel
if not WORDS:
# Raise error if trying to create Word Vectors without vectors extra
raise ImportError(
'Word vector models are not available - install "vectors" extra to enable. Otherwise, specify '
+ 'method="transformers" to use transformer backed models'
)

super().__init__(config, scoring, models)

def loadmodel(self, path):
# Ensure that vector path exists
if not path or not os.path.isfile(path):
Expand Down

0 comments on commit 79675f5

Please sign in to comment.