Saltar al contenido principal

CosineSimilarity

SimilarityMetric
DashAI.back.models.RAG.retrievers.similarity.CosineSimilarity

Cosine distance: one minus the cosine of the angle between two vectors.

The distance compares only the direction of the vectors, so their length does not change the ranking.

Methods​

distances(self, queries: numpy.ndarray | scipy.sparse._csr.csr_matrix, vectors: numpy.ndarray | scipy.sparse._csr.csr_matrix) -> numpy.ndarray

Defined on BaseSimilarityMetric

Return the distance of every query to every vector.

Parameters

queries : np.ndarray | csr_matrix
Query vectors, one per row.
vectors : np.ndarray | csr_matrix
Stored vectors, one per row.

Returns

np.ndarray
A (len(queries), len(vectors)) matrix of distances.

get_credential(self, name: str)

Defined on ConfigObject

Resolve a registered credential component by name.

Parameters

name : str
Credential component class name (e.g. "HuggingFaceCredential").

Returns

BaseCredential
An instance of the requested credential component.

get_schema(cls) -> dict

Defined on ConfigObject

Generates the component related Json Schema.

Returns

dict
Dictionary representing the Json Schema of the component.

validate_and_transform(self, raw_data: dict) -> dict

Defined on ConfigObject

It takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.

Parameters

raw_data : dict
A dictionary with the data provided by the user to initialize the model.

Returns

dict
A validated dictionary with the necessary objects.