Skip to content

Commit

Permalink
Change post-filters to pre-filters in BigQueryVectorStore (#554)
Browse files Browse the repository at this point in the history
BigQueryVectorStore's _create_filters are post-filters. Now that BigQuery Vector Search supports pre-filtering on stored columns (https://cloud.google.com/bigquery/docs/vector-index#stored-columns), we can change all post-filters to pre-filters.

Note that this requires storing the columns that are referenced by the pre-filter. This cannot be done in Langchain yet. If the required columns are not stored, then the pre-filters will act as post-filters. The results returned by the new post-filters will be a superset of the post-filters done currently, which can return less results.
  • Loading branch information
francislan authored Oct 21, 2024
1 parent 9e90ad2 commit af44de3
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ def _create_search_query(
full_query = f"""{embeddings_query}
{select_clause}
FROM VECTOR_SEARCH(
TABLE `{self.full_table_id}`,
(SELECT * FROM `{self.full_table_id}` WHERE {where_filter_expr}),
"{self.embedding_field}",
(SELECT row_num, {self.embedding_field} from embeddings),
(SELECT row_num, {self.embedding_field} FROM embeddings),
distance_type => "{self.distance_type}",
top_k => {k}
)
Expand All @@ -346,7 +346,6 @@ def _create_search_query(
FROM (
{full_query}
) AS result
WHERE {where_filter_expr}
ORDER BY row_num, score
"""
return full_query_wrapper
Expand Down

0 comments on commit af44de3

Please sign in to comment.