Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial metamodel definition #39

Merged
merged 12 commits into from
Sep 27, 2024
2 changes: 1 addition & 1 deletion src/monocle_apptrace/haystack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
logger = logging.getLogger(__name__)
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
HAYSTACK_METHODS = load_wrapper_from_config(
os.path.join(parent_dir, 'wrapper_config', 'haystack_methods.json'))
os.path.join(parent_dir, 'metamodel', 'maps', 'haystack_methods.json'))
2 changes: 1 addition & 1 deletion src/monocle_apptrace/langchain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
LANGCHAIN_METHODS = load_wrapper_from_config(
os.path.join(parent_dir, 'wrapper_config', 'lang_chain_methods.json'))
os.path.join(parent_dir, 'metamodel', 'maps', 'lang_chain_methods.json'))
2 changes: 1 addition & 1 deletion src/monocle_apptrace/llamaindex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def get_llm_span_name_for_openai(instance):

parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
LLAMAINDEX_METHODS = load_wrapper_from_config(
os.path.join(parent_dir, 'wrapper_config', 'llama_index_methods.json'))
os.path.join(parent_dir, 'metamodel', 'maps', 'llama_index_methods.json'))
47 changes: 47 additions & 0 deletions src/monocle_apptrace/metamodel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Monocle metamodel

## Overview
Monocle metamodel is the way to manage standardization across all supported GenAI component stack. It includes the list of components that Monocle can identify and extract metadata. This help understanding and analyzing the traces from applications that include multiple components and can evolve over time. This is one of core value that Monocle provides to it's user community.

## Meta model
The Monocle metamodel comprises of three things,
- Entity types, definitions of technology types and supported vendor implementations.
- A JSON format that overlays on top of Open Telemetry tracing format that includes the common attributes for each entity type.
- Map of component menthods to trace with instrumentation methods provided by Monocle.

### Entity type
The entity type defines the type of GenAI component that Monocle understand. The monocle instrumentation can extract the relevenat information for this entity. There are a fixed set of [entity types](./entity_types.py) that are defined by Monocle out of the box, eg workflow, model etc. As the GenAI landscape evolves, the Monocle community will introduce a new entity type if the current entities won't represent a new technology component.
Each entity types has number of supported technology components that Monocle handles out of the box, eg. LlamaIndex is a supported workflow. Monocle community will continue to expand the breadth of the project by adding more components.

### Span types
The GenAI application have specific [types of spans](./spans/README.md#span-types-and-events) where diffrent entities integrate. Monocle metamodel defines these types and specifies format for tracing data and metadata generated in such spans.

### Consistent trace format
Monocle generates [traces](../../../Monocle_User_Guide.md#traces) which comprises of [spans](../../../Monocle_User_Guide.md#spans). Note that Monocle trace is [OpenTelemetry format](https://opentelemetry.io/docs/concepts/signals/traces/) compatible. Each span is essentially a step in the execution that interacts with one of more GenAI technology components. The please refer to the [full spec of the json format](./span_format.json) and a detailed [example](./span_example.json).
The ```attribute``` section of the span includes a list of such entities that are used in that span.
The runtime data and metadata collected during the execution of that span are included in the ```events``` section of the trace (as per the Otel spec). Each entry in the event corrosponds to the entity involved in that trace execution if it has produced any runtime outputs.
Please see the [span format](./spans/README.md) for details.

### Instrumentation method map
The map dectates what Monocle tracing method is relevant for the a given GenAI tech component method/API. It also specifies the name for that span to set in the trace output.
```python
{
"package": "llama_index.core.base.base_query_engine",
"object": "BaseQueryEngine",
"method": "query",
"span_name": "llamaindex.query",
"wrapper_package": "wrap_common",
"wrapper_method": "task_wrapper"
}
```

## Extending the meta model
Monocle is highly extensible. This section describe when one would need to extend the meta model. Please refer to Monocle [User guide](../../../Monocle_User_Guide.md) and [Contributor guide](../../../Monocle_contributor_guide.md) for detailed steps.
### Trace a new method/API
If you have overloaded an existing functionality in one of the supported components by creating a new function. Monocle doesn't know that this function should be traced, say because it's calling an LLM. You could define a new mapping so Monocle instrumentation can trace this function the say way it handles other LLM invocation functions.

### Adding a new component provider
Let's say there's a new database that supports vector search capability which is not supported by the Monocle. In this case, first you'll need to add that database under the ``MonocleEntity.VectorDB`` list. Then you'll need to extend the method map and test if the existing Monocle tracing functions has logic to effectively trace the new component. If not, then you might need to implement new method to cover the gap and update the mapping table according.

### Support new type of entity
If there's new component that can't be mapped to any of the existing entity types, then it'll require extending the metamodel and implement new instrumetation to support it. We recommend you initiate a discussion with Monocle community to add the support.
54 changes: 54 additions & 0 deletions src/monocle_apptrace/metamodel/entities/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Monocle Entities
The entity type defines the type of GenAI component that Monocle understand. The monocle instrumentation can extract the relevenat information for this entity. There are a fixed set of [entity types](./entity_types.py) that are defined by Monocle out of the box, eg workflow, model etc. As the GenAI landscape evolves, the Monocle community will introduce a new entity type if the current entities won't represent a new technology component.

## Entity Types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can all the entity types be small case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep the vendor names starting with upper case. Do you have a strong preference all lowercase or if that's the convention generally followed, then we can switch to lower case.

Copy link
Contributor

@oi-raanne oi-raanne Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWS - capital case,
Azure - pascal case,
NVIDIA - capital case,
OpenAI- pascal case,
HuggingFace - pascal case

as type is in our control, we can keep it consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True .. I was trying to keep it consistent with the vendor name/brand, but I see your point. I guess it's better to be consistent here. Will change it all to all lowercase and camel case.

Following attributes are supported for all entities
| Name | Description | Required |
| - | - | - |
| name | Entity name generated by Monocle | Required |
| type | Monocle Entity type | True |

### MonocleEntity.Workflow
Workflow ie the core application code. Supported types are -
- generic
- langchain
- llama_index
- haystack

### MonocleEntity.Model
GenAI models. Supported types are -
- generic
- llm
- embedding
Following attributes are supported for all model type entities
| Name | Description | Required |
| - | - | - |
| model_name | Name of model | True |


### MonocleEntity.AppHosting
Application host services where the workflow code is run. Supported types are -
- generic
- aws_lambda
- aws_sagemaker
- azure_func
- github_codespace
- azure_mlw

### MonocleEntity.Inference
The model hosting infrastructure services. Supported types are -
- generic
- nvidia_triton
- openai
- azure_oai
- aws_sagemaker
- aws_bedrock
- hugging_face

### MonocleEntity.VectorStore
Vector search data stores. Supported types are -
- generic
- chroma
- aws_es
- milvus
- pinecone
157 changes: 157 additions & 0 deletions src/monocle_apptrace/metamodel/entities/entity_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"description": "Monocle entities represents kinds GenAI technology components and their implementations supported by Monocle",
"monocle_entities": [
{
"attributes" : [
{
"attribute_name": "name",
"attribute_description": "Monocle entity name",
"required": true
},
{
"attribute_name": "type",
"attribute_description": "Monocle entity type",
"required": true
}
],
"entities": [
{
"name": "workflow",
"attributes" : [],
"types": [
{
"type": "llama_index",
"attributes" : []
},
{
"type": "langchain",
"attributes" : []
},
{
"type": "haystack",
"attributes" : []
},
{
"type": "generic",
"attributes" : []
}
]
},
{
"name": "model",
"attributes" : [
{
"attribute_name": "model_name",
"attribute_description": "Model name",
"required": true
}
],
"types": [
{
"type": "llm",
"attributes" : []
},
{
"type": "embedding",
"attributes" : []
},
{
"type": "generic",
"attributes" : []
}
]
},
{
"name": "vector_store",
"attributes" : [],
"types": [
{
"type": "chroma",
"attributes" : []
},
{
"type": "aws_es",
"attributes" : []
},
{
"type": "milvus",
"attributes" : []
},
{
"type": "pinecone",
"attributes" : []
},
{
"type": "generic",
"attributes" : []
}
]
},
{
"name": "app_hosting",
"attributes" : [],
"types": [
{
"type": "aws_lambda",
"attributes" : []
},
{
"type": "aws_sagemaker",
"attributes" : []
},
{
"type": "azure_func",
"attributes" : []
},
{
"type": "azure_mlw",
"attributes" : []
},
{
"type": "github_codespace",
"attributes" : []
},
{
"type": "generic",
"attributes" : []
}
]
},
{
"name": "inference",
"attributes" : [],
"types": [
{
"type": "aws_sagemaker",
"attributes" : []
},
{
"type": "aws_bedrock",
"attributes" : []
},
{
"type": "azure_oai",
"attributes" : []
},
{
"type": "openai",
"attributes" : []
},
{
"type": "nvidia_triton",
"attributes" : []
},
{
"type": "hugging_face",
"attributes" : []
},
{
"type": "generic",
"attributes" : []
}
]
}
]
}
]
}
51 changes: 51 additions & 0 deletions src/monocle_apptrace/metamodel/entities/entity_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Monocle meta model:
# Monocle Entities --> Entity Type --> Entity

import enum

class MonocleEntity(enum):
# Supported Workflow/language frameworks
class Workflow(enum):
generic = 0
langchain = 1
llama_index = 2
haystack = 3

# Supported model types
class Model(enum):
generic = 0
llm = 1
embedding = 2

# Support Vector databases
class VectorStore(enum):
generic = 0
chroma = 1
aws_es = 2
Milvus = 3
Pinecone = 4

# Support application hosting frameworks
class AppHosting(enum):
generic = 0
aws_lambda = 1
aws_sagemaker = 2
azure_func = 3
github_codespace = 4
azure_mlw = 5

# Supported inference infra/services
class Inference(enum):
generic = 0
nvidia_triton = 1
openai = 2
azure_oai = 3
aws_sagemaker = 4
aws_bedrock = 5
hugging_face = 6

class SpanType(enum):
internal = 0
retrieval = 2
inference = 3
workflow = 4
Loading
Loading