Skip to content
Snippets Groups Projects
Commit a96f6b85 authored by jamescalam's avatar jamescalam
Browse files

fix: import

parent 805807f8
No related branches found
No related tags found
No related merge requests found
......@@ -412,6 +412,7 @@ class SparseEmbedding(BaseModel):
"""Sparse embedding interface. Primarily uses numpy operations for faster
operations.
"""
embedding: np.ndarray
class Config:
......@@ -425,36 +426,31 @@ class SparseEmbedding(BaseModel):
"Column 0 should contain index positions, and column 1 should contain respective values."
)
return cls(embedding=array)
@classmethod
def from_aurelio(cls, embedding: BM25Embedding):
arr = np.array([embedding.indices, embedding.values]).T
return cls.from_array(arr)
@classmethod
def from_dict(cls, sparse_dict: dict):
arr = np.array([list(sparse_dict.keys()), list(sparse_dict.values())]).T
return cls.from_array(arr)
def to_dict(self):
return {
i: v for i, v in zip(
self.embedding[:,0].astype(int),
self.embedding[:,1]
)
i: v for i, v in zip(self.embedding[:, 0].astype(int), self.embedding[:, 1])
}
def to_pinecone(self):
return {
"indices": self.embedding[:, 0].astype(int).tolist(),
"values": self.embedding[:, 1].tolist(),
}
# dictionary interface
def items(self):
return [
(i, v) for i, v in zip(
self.embedding[:,0].astype(int),
self.embedding[:,1]
)
(i, v)
for i, v in zip(self.embedding[:, 0].astype(int), self.embedding[:, 1])
]
......@@ -7,7 +7,7 @@ from typing import Optional
from semantic_router.encoders import DenseEncoder, CohereEncoder, OpenAIEncoder
from semantic_router.index.pinecone import PineconeIndex
from semantic_router.schema import Utterance
from semantic_router.routers.base import SemanticRouter
from semantic_router.routers import SemanticRouter
from semantic_router.route import Route
from platform import python_version
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment