Skip to content

Commit

Permalink
fix: import
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescalam committed Nov 27, 2024
1 parent 805807f commit a96f6b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions semantic_router/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ class SparseEmbedding(BaseModel):
"""Sparse embedding interface. Primarily uses numpy operations for faster
operations.
"""

embedding: np.ndarray

class Config:
Expand All @@ -425,36 +426,31 @@ def from_array(cls, array: np.ndarray):
"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])
]
2 changes: 1 addition & 1 deletion tests/unit/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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

Expand Down

0 comments on commit a96f6b8

Please sign in to comment.