Skip to content

Commit

Permalink
fixed BQ vector search batch_search (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
lspataroG authored Dec 12, 2024
1 parent 999eb78 commit 11cf22d
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def _create_search_query(
if table_to_query is not None:
embeddings_query = f"""
with embeddings as (
SELECT {self.embedding_field}, ROW_NUMBER() OVER() as row_num
SELECT {self.embedding_field}, row_num
from `{table_to_query}`
)"""

Expand Down Expand Up @@ -390,14 +390,16 @@ def _create_temp_bq_table(
df = pd.DataFrame([])

df[self.embedding_field] = embeddings
df["row_num"] = list(range(len(df)))
table_id = (
f"{self.project_id}."
f"{self.temp_dataset_name}."
f"{self.table_name}_{uuid.uuid4().hex}"
)

schema = [
bigquery.SchemaField(self.embedding_field, "FLOAT64", mode="REPEATED")
bigquery.SchemaField(self.embedding_field, "FLOAT64", mode="REPEATED"),
bigquery.SchemaField("row_num", "INT64"),
]
table_ref = bigquery.Table(table_id, schema=schema)
table = self._bq_client.create_table(table_ref)
Expand Down Expand Up @@ -483,7 +485,7 @@ def batch_search(
)

if queries is not None:
embeddings = self.embedding.embed_documents(queries)
embeddings = [self.embedding.embed_query(query) for query in queries]

if embeddings is None:
raise ValueError("Could not obtain embeddings - value is None.")
Expand Down

0 comments on commit 11cf22d

Please sign in to comment.