Find Most Similar • AI Agent SDK
find_most_similar: Find the most similar texts to a query.
find_most_similar
Method
</div>
This is a method of the EmbeddingAgent class in the embedding_agent module.
Find the most similar texts to a query.
Signature
def find_most_similar(query: str, candidates: List[str], top_k: int, model: Optional[str]) -> List[Dict[str, Any]]Parameters
ParamField
strQuery text
ParamField
List[str]List of candidate texts to compare
ParamField
intNumber of top results to return
ParamField
Optional[str]Override model for this call **kwargs: Additional parameters
Returns
ResponseField
List[Dict[str, Any]]List of dicts with ‘text’, ‘score’, and ‘index’ keys
Usage
agent = EmbeddingAgent()
results = agent.find_most_similar(
"What is AI?",
["Artificial intelligence is...", "Machine learning...", "Deep learning..."],
top_k=2
)
for r in results:
print(f"{r['score']:.2f}: {r['text'][:50]}...")Uses
embed_batchscores.sort
Source
View on GitHubpraisonaiagents/agent/embedding_agent.py at line 308