2020
2121import google .cloud .bigquery as bigquery
2222
23+ import bigframes .core .sql
24+ import bigframes .dataframe
2325import bigframes .ml .utils as utils
2426
2527if typing .TYPE_CHECKING :
26- import bigframes .dataframe as dataframe
2728 import bigframes .series as series
2829 import bigframes .session
2930
@@ -91,15 +92,15 @@ def create_vector_index(
9192def vector_search (
9293 base_table : str ,
9394 column_to_search : str ,
94- query : Union [" dataframe.DataFrame" , " series.Series" ],
95+ query : Union [bigframes . dataframe .DataFrame , series .Series ],
9596 * ,
9697 query_column_to_search : Optional [str ] = None ,
9798 top_k : Optional [int ] = None ,
9899 distance_type : Optional [Literal ["euclidean" , "cosine" , "dot_product" ]] = None ,
99100 fraction_lists_to_search : Optional [float ] = None ,
100101 use_brute_force : Optional [bool ] = None ,
101102 allow_large_results : Optional [bool ] = None ,
102- ) -> dataframe .DataFrame :
103+ ) -> bigframes . dataframe .DataFrame :
103104 """
104105 Conduct vector search which searches embeddings to find semantically similar entities.
105106
@@ -108,7 +109,6 @@ def vector_search(
108109
109110 **Examples:**
110111
111-
112112 >>> import bigframes.pandas as bpd
113113 >>> import bigframes.bigquery as bbq
114114
@@ -250,12 +250,8 @@ def vector_search(
250250
251251
252252def search (
253- data_to_search : Union [" dataframe.DataFrame" , " series.Series" ],
253+ data_to_search : Union [bigframes . dataframe .DataFrame , series .Series ],
254254 search_query : str ,
255- * ,
256- json_scope : Optional [str ] = None ,
257- analyzer : Optional [str ] = None ,
258- analyzer_options : Optional [str ] = None ,
259255) -> series .Series :
260256 """
261257 The SEARCH function checks to see whether a BigQuery table or other search
@@ -288,46 +284,28 @@ def search(
288284 search_query (str):
289285 A STRING literal, or a STRING constant expression that represents
290286 the terms of the search query.
291- json_scope (str, optional):
292- A named argument with a STRING value. Takes one of the following
293- values to indicate the scope of JSON data to be searched. It has no
294- effect if data_to_search isn't a JSON value or doesn't contain a
295- JSON field.
296- analyzer (str, optional):
297- A named argument with a STRING value. Takes one of the following
298- values to indicate the text analyzer to use: 'LOG_ANALYZER',
299- 'NO_OP_ANALYZER', 'PATTERN_ANALYZER'.
300- analyzer_options (str, optional):
301- A named argument with a JSON-formatted STRING value. Takes a list
302- of text analysis rules.
303287
304288 Returns:
305289 bigframes.series.Series: A new Series with the boolean result.
306290 """
307291 import bigframes .operations .search_ops as search_ops
308292 import bigframes .series
309293
310- if not isinstance (data_to_search , (bigframes .series .Series , bigframes .dataframe .DataFrame )):
294+ if not isinstance (
295+ data_to_search , (bigframes .series .Series , bigframes .dataframe .DataFrame )
296+ ):
311297 raise ValueError ("data_to_search must be a Series or DataFrame" )
312298
313299 if isinstance (data_to_search , bigframes .dataframe .DataFrame ):
314- # SEARCH on a table (or dataframe) treats it as a STRUCT
315- # We need to apply the op on the dataframe, which should handle it as a struct or row
316- # However, unary ops are usually applied on Series.
317- # But DataFrame can be passed if we convert it to a struct first?
318- # Or does DataFrame support _apply_unary_op?
319- # bigframes.dataframe.DataFrame does not have _apply_unary_op.
320- # We can convert DataFrame to a Series of Structs.
321- # But SEARCH in BigQuery can take a table reference which is evaluated as a STRUCT.
322- # So creating a struct from all columns seems correct.
300+ # SEARCH on a table (or dataframe) treats it as a STRUCT. For easier
301+ # application of a scalar unary op, we convert to a struct proactively
302+ # in the expression.
323303 import bigframes .bigquery ._operations .struct as struct_ops
304+
324305 data_to_search = struct_ops .struct (data_to_search )
325306
326307 return data_to_search ._apply_unary_op (
327308 search_ops .SearchOp (
328309 search_query = search_query ,
329- json_scope = json_scope ,
330- analyzer = analyzer ,
331- analyzer_options = analyzer_options ,
332310 )
333311 )
0 commit comments