20
20
from typing_extensions import TypeGuard
21
21
22
22
from openinference .semconv .trace import (
23
+ EmbeddingAttributes ,
23
24
ImageAttributes ,
24
25
MessageAttributes ,
25
26
MessageContentAttributes ,
33
34
)
34
35
35
36
from ._types import (
37
+ Embedding ,
36
38
Message ,
37
39
OpenInferenceLLMProvider ,
38
40
OpenInferenceLLMSystem ,
53
55
from _typeshed import DataclassInstance
54
56
55
57
58
+ def get_embedding_attributes (
59
+ * ,
60
+ model_name : Optional [str ] = None ,
61
+ embeddings : Optional [List [Embedding ]] = None ,
62
+ ) -> Dict [str , Any ]:
63
+ embedding_attributes : Dict [str , AttributeValue ] = {}
64
+ if model_name is not None :
65
+ embedding_attributes [EMBEDDING_MODEL_NAME ] = model_name
66
+ if isinstance (embeddings , list ):
67
+ for index , embedding in enumerate (embeddings ):
68
+ if (text := embedding .get ("text" )) is not None :
69
+ key = f"{ EMBEDDING_EMBEDDINGS } .{ index } .{ EMBEDDING_TEXT } "
70
+ embedding_attributes [key ] = text
71
+ if (vector := embedding .get ("vector" )) is not None :
72
+ key = f"{ EMBEDDING_EMBEDDINGS } .{ index } .{ EMBEDDING_VECTOR } "
73
+ embedding_attributes [key ] = vector
74
+ return embedding_attributes
75
+
76
+
56
77
def get_context_attributes (
57
78
* ,
58
79
session_id : Optional [str ] = None ,
@@ -413,6 +434,10 @@ def get_llm_tool_attributes(
413
434
return attributes
414
435
415
436
437
+ # embedding attributes
438
+ EMBEDDING_TEXT = EmbeddingAttributes .EMBEDDING_TEXT
439
+ EMBEDDING_VECTOR = EmbeddingAttributes .EMBEDDING_VECTOR
440
+
416
441
# image attributes
417
442
IMAGE_URL = ImageAttributes .IMAGE_URL
418
443
@@ -432,6 +457,8 @@ def get_llm_tool_attributes(
432
457
433
458
434
459
# span attributes
460
+ EMBEDDING_EMBEDDINGS = SpanAttributes .EMBEDDING_EMBEDDINGS
461
+ EMBEDDING_MODEL_NAME = SpanAttributes .EMBEDDING_MODEL_NAME
435
462
INPUT_MIME_TYPE = SpanAttributes .INPUT_MIME_TYPE
436
463
INPUT_VALUE = SpanAttributes .INPUT_VALUE
437
464
LLM_INPUT_MESSAGES = SpanAttributes .LLM_INPUT_MESSAGES
0 commit comments