This guide explains how to extend SMPTE-Copilot by adding new components to any module.
To add a new component to any module, follow these steps (we'll use the embeddings module as an example, but the process is identical for all modules):
Edit src/embeddings/types.py and add the new type:
class EmbeddingModelType(str, Enum):
HUGGINGFACE = "huggingface"
OPENAI = "openai"
COHERE = "cohere" # New typeCreate a new file, for example src/embeddings/cohere.py:
"""Cohere embedding model implementation."""
from __future__ import annotations
from typing import Dict, Any
from langchain_cohere import CohereEmbeddings
from .protocol import Embeddings
def create_cohere_embedding(config: Dict[str, Any]) -> Embeddings:
"""Create Cohere embedding model.
Parameters
----------
config
Configuration dictionary. Common parameters include:
- model: str (optional) - Model name
- cohere_api_key: str (optional) - API key
- Other parameters supported by CohereEmbeddings constructor.
Returns
-------
Embeddings instance.
"""
try:
return CohereEmbeddings(**config)
except Exception as e:
raise ValueError(f"Failed to create Cohere embedding model: {e}") from eImportant: The function must:
- Receive a
Dict[str, Any]as parameter - Return an instance that implements the module's Protocol (
Embeddingsin this case) - Handle errors appropriately
Edit src/embeddings/factory.py and add the import and registration:
from .cohere import create_cohere_embedding # Add import
# At the end of the file, register the new implementation in the registry
EmbeddingModelFactory.register(EmbeddingModelType.COHERE)(create_cohere_embedding)The registration happens automatically at module import time (see Dynamic Factory Pattern with Registry for details on how the registry works).
If necessary, update src/embeddings/__init__.py to export any constants or helpers related to the new component.
Add the configuration for the new component in config.yaml:
embedding:
embed_name: cohere # Use the Enum value (must match the string value in types.py)
embed_config:
model: "embed-english-v3.0"
cohere_api_key: "${COHERE_API_KEY}" # Can use environment variables- Add type to Enum in
types.py - Create implementation file with
create_*function - Import and register in
factory.py(registry populated automatically) - Configure in
config.yaml(if applicable)
This same process applies to:
chunkers/: Add new chunking algorithmsloaders/: Add new loader types (DOCX, HTML, etc.)retrievers/: Add new retrieval strategiesvector_stores/: Add new vector stores (Pinecone, Weaviate, etc.)
For more information about the architecture patterns used, see the Architecture documentation. To understand how to configure new components, see the Configuration guide.