@@ -151,7 +151,7 @@ def __post_init__(self):
151151@dataclass
152152class HybridQuery :
153153 """
154- Hyrbid query. Could be used for dense-only or sparse-only or hybrid queries.
154+ Hybrid query. Could be used for dense-only or sparse-only or hybrid queries.
155155
156156 dense_embedding (List[float]):
157157 Optional. The dense part of the hybrid queries.
@@ -328,6 +328,10 @@ def from_embedding(self, embedding: match_service_pb2.Embedding) -> "MatchNeighb
328328 if embedding .sparse_embedding :
329329 self .sparse_embedding_values = embedding .sparse_embedding .float_val
330330 self .sparse_embedding_dimensions = embedding .sparse_embedding .dimension
331+
332+ # retrieve embedding metadata
333+ if embedding .embedding_metadata :
334+ self .embedding_metadata = embedding .embedding_metadata
331335 return self
332336
333337
@@ -1883,7 +1887,7 @@ def find_neighbors(
18831887 [
18841888 MatchNeighbor (
18851889 id = neighbor .datapoint .datapoint_id ,
1886- distance = neighbor .distance ,
1890+ distance = neighbor .distance if neighbor . distance else None ,
18871891 sparse_distance = (
18881892 neighbor .sparse_distance if neighbor .sparse_distance else None
18891893 ),
@@ -2219,19 +2223,18 @@ def match(
22192223 # Wrap the results in MatchNeighbor objects and return
22202224 match_neighbors_response = []
22212225 for resp in response .responses [0 ].responses :
2222- match_neighbors_id_map = {}
2226+ embedding_map = {embedding .id : embedding for embedding in resp .embeddings }
2227+ neighbors_list = []
22232228 for neighbor in resp .neighbor :
2224- match_neighbors_id_map [ neighbor . id ] = MatchNeighbor (
2229+ match_neighbor = MatchNeighbor (
22252230 id = neighbor .id ,
2226- distance = neighbor .distance ,
2231+ distance = neighbor .distance if neighbor . distance else None ,
22272232 sparse_distance = (
22282233 neighbor .sparse_distance if neighbor .sparse_distance else None
22292234 ),
22302235 )
2231- for embedding in resp .embeddings :
2232- if embedding .id in match_neighbors_id_map :
2233- match_neighbors_id_map [embedding .id ] = match_neighbors_id_map [
2234- embedding .id
2235- ].from_embedding (embedding = embedding )
2236- match_neighbors_response .append (list (match_neighbors_id_map .values ()))
2236+ if neighbor .id in embedding_map :
2237+ match_neighbor .from_embedding (embedding = embedding_map [neighbor .id ])
2238+ neighbors_list .append (match_neighbor )
2239+ match_neighbors_response .append (neighbors_list )
22372240 return match_neighbors_response
0 commit comments