chore: telemetry for rankers, readers, retrievers, writers (#6075)

* add telemetry to pipelines 2.0

* only collect data if telemetry is on

* reno

* add downsampling

* typing

* manual tests

* pylint

* simplify code

* Update haystack/preview/telemetry/__init__.py

* look for _telemetry_data

* rather index by component type

* black

* mypy

* error handling

* comment

* review feedback & small improvements

* defaultdict

* stray changes

* try-catch

* method instead of attribute

* fixes

* remove print statements

* lint

* invert condition

* always send the first event of the day

* collect specs

* track 2nd and 3rd events too

* send first event and then max 1 event a minute

* rename constant

* black

* add test

* add telemetry for rankers readers and retrievers

* get only the type of docstore, not the whole object
This commit is contained in:
ZanSara 2023-10-16 17:02:24 +01:00 committed by GitHub
parent 490de4e119
commit 6b097928ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 0 deletions

View File

@ -56,6 +56,12 @@ class SimilarityRanker:
self.model = None
self.tokenizer = None
def _get_telemetry_data(self) -> Dict[str, Any]:
"""
Data that is sent to Posthog for usage analytics.
"""
return {"model": str(self.model_name_or_path)}
def warm_up(self):
"""
Warm up the model and tokenizer used in scoring the documents.

View File

@ -67,6 +67,12 @@ class ExtractiveReader:
self.no_answer = no_answer
self.calibration_factor = calibration_factor
def _get_telemetry_data(self) -> Dict[str, Any]:
"""
Data that is sent to Posthog for usage analytics.
"""
return {"model": self.model_name_or_path}
def to_dict(self) -> Dict[str, Any]:
"""
Serialize this component to a dictionary.

View File

@ -41,6 +41,12 @@ class MemoryBM25Retriever:
self.top_k = top_k
self.scale_score = scale_score
def _get_telemetry_data(self) -> Dict[str, Any]:
"""
Data that is sent to Posthog for usage analytics.
"""
return {"document_store": type(self.document_store).__name__}
def to_dict(self) -> Dict[str, Any]:
"""
Serialize this component to a dictionary.

View File

@ -44,6 +44,12 @@ class MemoryEmbeddingRetriever:
self.scale_score = scale_score
self.return_embedding = return_embedding
def _get_telemetry_data(self) -> Dict[str, Any]:
"""
Data that is sent to Posthog for usage analytics.
"""
return {"document_store": type(self.document_store).__name__}
def to_dict(self) -> Dict[str, Any]:
"""
Serialize this component to a dictionary.

View File

@ -19,6 +19,12 @@ class DocumentWriter:
self.document_store = document_store
self.policy = policy
def _get_telemetry_data(self) -> Dict[str, Any]:
"""
Data that is sent to Posthog for usage analytics.
"""
return {"document_store": type(self.document_store).__name__}
def to_dict(self) -> Dict[str, Any]:
"""
Serialize this component to a dictionary.