trulens.feedback.embeddings¶
trulens.feedback.embeddings
¶
Classes¶
Embeddings
¶
Bases: WithClassInfo
, SerialModel
Embedding related feedback function implementations.
Attributes¶
tru_class_info
instance-attribute
¶
tru_class_info: Class
Class information of this pydantic object for use in deserialization.
Using this odd key to not pollute attribute names in whatever class we mix this into. Should be the same as CLASS_INFO.
Functions¶
load
staticmethod
¶
load(obj, *args, **kwargs)
Deserialize/load this object using the class information in tru_class_info to lookup the actual class that will do the deserialization.
model_validate
classmethod
¶
model_validate(*args, **kwargs) -> Any
Deserialized a jsonized version of the app into the instance of the class it was serialized from.
Note
This process uses extra information stored in the jsonized object and handled by WithClassInfo.
__init__
¶
__init__(embed_model: BaseEmbedding)
Instantiates embeddings for feedback functions.
Example
Below is just one example. Embedders from llama-index are supported: https://docs.llamaindex.ai/en/latest/module_guides/models/embeddings/
from llama_index.embeddings.openai import OpenAIEmbedding
from trulens.feedback.embeddings import Embeddings
embed_model = OpenAIEmbedding()
f_embed = Embedding(embed_model=embed_model)
PARAMETER | DESCRIPTION |
---|---|
embed_model |
Supports embedders from llama-index: https://docs.llamaindex.ai/en/latest/module_guides/models/embeddings/
TYPE:
|
cosine_distance
¶
Runs cosine distance on the query and document embeddings
Example
Below is just one example. Embedders from llama-index are supported: https://docs.llamaindex.ai/en/latest/module_guides/models/embeddings/
from llama_index.embeddings.openai import OpenAIEmbedding
from trulens.feedback.embeddings import Embeddings
embed_model = OpenAIEmbedding()
# Create the feedback function
f_embed = feedback.Embeddings(embed_model=embed_model)
f_embed_dist = feedback.Feedback(f_embed.cosine_distance) .on_input_output()
PARAMETER | DESCRIPTION |
---|---|
query |
A text prompt to a vector DB.
TYPE:
|
document |
The document returned from the vector DB.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
the embedding vector distance |
manhattan_distance
¶
Runs L1 distance on the query and document embeddings
Example
Below is just one example. Embedders from llama-index are supported: https://docs.llamaindex.ai/en/latest/module_guides/models/embeddings/
from llama_index.embeddings.openai import OpenAIEmbedding
from trulens.feedback.embeddings import Embeddings
embed_model = OpenAIEmbedding()
# Create the feedback function
f_embed = feedback.Embeddings(embed_model=embed_model)
f_embed_dist = feedback.Feedback(f_embed.manhattan_distance) .on_input_output()
PARAMETER | DESCRIPTION |
---|---|
query |
A text prompt to a vector DB.
TYPE:
|
document |
The document returned from the vector DB.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
the embedding vector distance |
euclidean_distance
¶
Runs L2 distance on the query and document embeddings
Example
Below is just one example. Embedders from llama-index are supported: https://docs.llamaindex.ai/en/latest/module_guides/models/embeddings/
from llama_index.embeddings.openai import OpenAIEmbedding
from trulens.feedback.embeddings import Embeddings
embed_model = OpenAIEmbedding()
# Create the feedback function
f_embed = feedback.Embeddings(embed_model=embed_model)
f_embed_dist = feedback.Feedback(f_embed.euclidean_distance) .on_input_output()
PARAMETER | DESCRIPTION |
---|---|
query |
A text prompt to a vector DB.
TYPE:
|
document |
The document returned from the vector DB.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
the embedding vector distance |