Similarity (embeddings)
The similar assertion checks if an embedding of the LLM's output
is semantically similar to the expected value,
using a cosine similarity threshold.
By default, embeddings are computed via OpenAI's text-embedding-ada-002 model.
Example:
assert:
- type: similar
value: 'The expected output'
threshold: 0.8
Overriding the provider
By default similar will use OpenAI. To specify the model that creates the embeddings, do one of the following:
Use
test.optionsordefaultTest.optionsto override the provider across the entire test suite:defaultTest:
options:
provider: azureopenai:embedding:text-embedding-ada-002
tests:
assert:
- type: similar
value: Hello worldSet
assertion.provideron a per-assertion basis:tests:
assert:
- type: similar
value: Hello world
provider: huggingface:feature-extraction:sentence-transformers/all-MiniLM-L6-v2