> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Find Most Similar • AI Agent SDK

> find_most_similar: Find the most similar texts to a query.

# find\_most\_similar

<div className="flex items-center gap-2">
  <Badge color="purple">Method</Badge>
</div>

> This is a method of the [**EmbeddingAgent**](../classes/EmbeddingAgent) class in the [**embedding\_agent**](../modules/embedding_agent) module.

Find the most similar texts to a query.

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def find_most_similar(query: str, candidates: List[str], top_k: int, model: Optional[str]) -> List[Dict[str, Any]]
```

## Parameters

<ParamField query="query" type="str" required={true}>
  Query text
</ParamField>

<ParamField query="candidates" type="List" required={true}>
  List of candidate texts to compare
</ParamField>

<ParamField query="top_k" type="int" required={false} default="5">
  Number of top results to return
</ParamField>

<ParamField query="model" type="Optional" required={false}>
  Override model for this call \*\*kwargs: Additional parameters
</ParamField>

### Returns

<ResponseField name="Returns" type="List[Dict[str, Any]]">
  List of dicts with 'text', 'score', and 'index' keys
</ResponseField>

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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_batch`
* `scores.sort`

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/agent/embedding_agent.py#L309">
  `praisonaiagents/agent/embedding_agent.py` at line 309
</Card>
