Add the BQ job usage tracking from LangChain (#17123)

- **Description:**
Add the BQ job usage tracking from LangChain

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
pull/17490/head
Ashley Xu 4 months ago committed by GitHub
parent 5dca107621
commit f746a73e26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,25 @@
"""Utilities to use Google provided components."""
from importlib import metadata
from typing import Any, Optional
def get_client_info(module: Optional[str] = None) -> Any:
r"""Returns a custom user agent header.
Args:
module (Optional[str]):
Optional. The module for a custom user agent header.
Returns:
google.api_core.gapic_v1.client_info.ClientInfo
"""
from google.api_core.gapic_v1.client_info import ClientInfo
langchain_version = metadata.version("langchain")
client_library_version = (
f"{langchain_version}-{module}" if module else langchain_version
)
return ClientInfo(
client_library_version=client_library_version,
user_agent=f"langchain/{client_library_version}",
)

@ -16,6 +16,7 @@ from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_core.vectorstores import VectorStore
from langchain_community.utils.google import get_client_info
from langchain_community.vectorstores.utils import (
DistanceStrategy,
maximal_marginal_relevance,
@ -30,7 +31,6 @@ DEFAULT_TOP_K = 4 # default number of documents returned from similarity search
_MIN_INDEX_ROWS = 5000 # minimal number of rows for creating an index
_INDEX_CHECK_PERIOD_SECONDS = 60 # Do not check for index more often that this.
_vector_table_lock = Lock() # process-wide BigQueryVectorSearch table lock
@ -90,8 +90,12 @@ class BigQueryVectorSearch(VectorStore):
try:
from google.cloud import bigquery
client_info = get_client_info(module="bigquery-vector-search")
self.bq_client = bigquery.Client(
project=project_id, location=location, credentials=credentials
project=project_id,
location=location,
credentials=credentials,
client_info=client_info,
)
except ModuleNotFoundError:
raise ImportError(

Loading…
Cancel
Save