mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
nomic[patch]: release 0.0.2, dimensionality (#17534)
- nomic[patch]: release 0.0.2 - x
This commit is contained in:
@@ -3,6 +3,7 @@ from typing import List, Optional
|
||||
|
||||
import nomic # type: ignore
|
||||
from langchain_core.embeddings import Embeddings
|
||||
from nomic import embed # type: ignore
|
||||
|
||||
|
||||
class NomicEmbeddings(Embeddings):
|
||||
@@ -21,6 +22,7 @@ class NomicEmbeddings(Embeddings):
|
||||
*,
|
||||
model: str,
|
||||
nomic_api_key: Optional[str] = None,
|
||||
dimensionality: Optional[int] = None,
|
||||
):
|
||||
"""Initialize NomicEmbeddings model.
|
||||
|
||||
@@ -33,6 +35,7 @@ class NomicEmbeddings(Embeddings):
|
||||
if _api_key:
|
||||
nomic.login(_api_key)
|
||||
self.model = model
|
||||
self.dimensionality = dimensionality
|
||||
|
||||
def embed(self, texts: List[str], *, task_type: str) -> List[List[float]]:
|
||||
"""Embed texts.
|
||||
@@ -42,10 +45,13 @@ class NomicEmbeddings(Embeddings):
|
||||
task_type: the task type to use when embedding. One of `search_query`,
|
||||
`search_document`, `classification`, `clustering`
|
||||
"""
|
||||
# TODO: do this via nomic.embed when fixed in nomic sdk
|
||||
from nomic import embed
|
||||
|
||||
output = embed.text(texts=texts, model=self.model, task_type=task_type)
|
||||
output = embed.text(
|
||||
texts=texts,
|
||||
model=self.model,
|
||||
task_type=task_type,
|
||||
dimensionality=self.dimensionality,
|
||||
)
|
||||
return output["embeddings"]
|
||||
|
||||
def embed_documents(self, texts: List[str]) -> List[List[float]]:
|
||||
|
||||
Reference in New Issue
Block a user