similarity • AI Agent SDK
similarity: Calculate cosine similarity between two texts.
similarity
Method
</div>
This is a method of the EmbeddingAgent class in the embedding_agent module.
Calculate cosine similarity between two texts.
Signature
def similarity(text1: str, text2: str, model: Optional[str]) -> floatParameters
ParamField
strFirst text
ParamField
strSecond text
ParamField
Optional[str]Override model for this call **kwargs: Additional parameters
Returns
ResponseField
floatCosine similarity score (0.0 to 1.0)
Usage
agent = EmbeddingAgent()
score = agent.similarity("Hello", "Hi there")
print(f"Similarity: {score:.2f}")Uses
embed_batch
Source
View on GitHubpraisonaiagents/agent/embedding_agent.py at line 265