Skip to content

Commit

Permalink
Fix pylint issues
Browse files Browse the repository at this point in the history
Signed-off-by: Aakash Thatte <[email protected]>
  • Loading branch information
sky-2002 committed Feb 26, 2024
1 parent 7701be7 commit d9f6a45
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions gptcache/embedding/nomic.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
"""Nomic embedding integration"""

import numpy as np

from gptcache.utils import import_nomic
from gptcache.embedding.base import BaseEmbedding

import_nomic()

import nomic
from nomic import embed
import nomic # pylint: disable=C0413
from nomic import embed # pylint: disable=C0413

class Nomic(BaseEmbedding):
"""Generate text embedding for given text using Cohere.
"""

def __init__(self,
def __init__(self,
model: str = "nomic-embed-text-v1.5",
api_key: str = None,
task_type: str = "search_document",
dimensionality: int = None,
) -> None:
dimensionality: int = None) -> None:
"""Generate text embedding for given text using Nomic embed.
:param model: model name, defaults to 'nomic-embed-text-v1.5'.
Expand All @@ -42,14 +41,13 @@ def __init__(self,
dimensionality=64)
embed = encoder.to_embeddings(test_sentence)
"""

# Login to nomic
nomic.cli.login(token=api_key)

self._model = model
self._task_type = task_type
self._dimensionality = dimensionality

def to_embeddings(self, data, **_):
"""Generate embedding given text input
Expand All @@ -60,7 +58,7 @@ def to_embeddings(self, data, **_):
"""
if not isinstance(data, list):
data = [data]

# Response will be a dictionary with key 'embeddings'
# and value will be a list of lists
response = embed.text(
Expand All @@ -70,7 +68,7 @@ def to_embeddings(self, data, **_):
dimensionality=self._dimensionality)
embeddings = response['embeddings']
return np.array(embeddings).astype("float32").squeeze(0)

@property
def dimension(self):
"""Embedding dimension.
Expand All @@ -81,6 +79,4 @@ def dimension(self):
foo_emb = self.to_embeddings("foo")
self._dimensionality = len(foo_emb)
return self._dimensionality



0 comments on commit d9f6a45

Please sign in to comment.