MCPcopy Create free account
hub / github.com/BIT-DataLab/LakeBench / column_query

Method column_query

union/D3L/d3l/querying/query_engine.py:107–167  ·  view source on GitHub ↗

Perform column-level top-k nearest neighbour search over the configured LSH backends. Parameters ---------- column : pd.Series The column query as a Pandas Series. The series name will give the name queries. The series values will

(
        self,
        column: pd.Series,
        aggregator: Optional[callable] = None,
        k: Optional[int] = None,
    )

Source from the content-addressed store, hash-verified

105 return np.average(scores, axis=0, weights=ecdf_weights)
106
107 def column_query(
108 self,
109 column: pd.Series,
110 aggregator: Optional[callable] = None,
111 k: Optional[int] = None,
112 ) -> Iterable[Tuple[str, Iterable[float]]]:
113 """
114 Perform column-level top-k nearest neighbour search over the configured LSH backends.
115 Parameters
116 ----------
117 column : pd.Series
118 The column query as a Pandas Series.
119 The series name will give the name queries.
120 The series values will give the value queries.
121 aggregator: Optional[callable] = None
122 An aggregating function used to merge the results of all configured backends.
123 If None then all scores are returned.
124 k : Optional[int]
125 Only the top-k neighbours will be retrieved from each backend.
126 Then, these results are aggregated using the aggregator function and the results re-ranked to retrieve
127 the top-k aggregated neighbours.
128 If this is None all results are retrieved.
129
130 Returns
131 -------
132 Iterable[Tuple[str, Iterable[float]]]
133 A collection of (column id, aggregated score values) pairs.
134 The scores are the values returned by the backends or one aggregated value if an aggregator is passed.
135 """
136
137 results = defaultdict(lambda: [0.0] * len(self.query_backends))
138 query_name = str(column.name)
139 query_value = column.values.tolist()
140
141 for i, backend in enumerate(self.query_backends):
142 if isinstance(backend, NameIndex):
143 query_results = backend.query(query=query_name, k=k)
144 else:
145 query_results = backend.query(query=query_value, k=k)
146
147 for rid, score in query_results:
148 results[rid][i] = score
149
150 if aggregator is None:
151 # If not aggregation is used results are sorted by the mean of the scores.
152 # Reverse sorting because the scores are similarities.
153 results = sorted(
154 results.items(),
155 key=lambda items: sum(items[1]) / len(self.query_backends),
156 reverse=True,
157 )
158 else:
159 results = {rid: [aggregator(scores)] for rid, scores in results.items()}
160 # Reverse sorting because the scores are similarities.
161 results = sorted(
162 results.items(), key=lambda items: items[1][0], reverse=True
163 )
164

Callers 1

table_queryMethod · 0.95

Calls 1

queryMethod · 0.45

Tested by

no test coverage detected