mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-09 13:00:34 +00:00
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>
This commit is contained in:
parent
5dca107621
commit
f746a73e26
25
libs/community/langchain_community/utils/google.py
Normal file
25
libs/community/langchain_community/utils/google.py
Normal file
@ -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…
Reference in New Issue
Block a user