Skip to content

Commit

Permalink
Add documentation for custom embeddings model and small tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
drazvan committed Sep 1, 2023
1 parent 2d0ace1 commit acb49c4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for [custom configuration data](./docs/user_guide/configuration-guide.md#custom-data).
- Example for using [custom LLM and multiple KBs](./examples/multi_kb/README.md)
- Support for [`PROMPTS_DIR`](./docs/user_guide/advanced/prompt-customization.md#prompt-configuration).
- [#101](https://github.com/NVIDIA/NeMo-Guardrails/pull/101) Support for [using OpenAI embeddings](./docs/user_guide/configuration-guide.md#the-embeddings-model) models in addition to SentenceTransformers.

### Fixed

Expand Down
22 changes: 22 additions & 0 deletions docs/user_guide/configuration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,28 @@ models:
```


### The Embeddings Model

To configure the embeddings model that is used for the various steps in the [guardrails process](../architecture/README.md) (e.g., canonical form generation, next step generation) you can add a model configuration in the `models` key as shown below:

```yaml
models:
- ...
- type: embedding
engine: SentenceTransformers
model: all-MiniLM-L6-v2
```

The `SentenceTransformers` engine is the default one and uses the `all-MiniLM-L6-v2` model. NeMo Guardrails also supports using OpenAI models for computing the embeddings, e.g.:

```yaml
models:
- ...
- type: embedding
engine: openai
model: text-embedding-ada-002
```

### General Instruction

The general instruction (similar to a system prompt) gets appended at the beginning of every prompt, and you can configure it as shown below:
Expand Down
7 changes: 5 additions & 2 deletions nemoguardrails/actions/llm/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ def __init__(
self.llm = llm
self.verbose = verbose

# If we have a customized embedding model, we'll use it.
# The default embeddings model is using SentenceTransformers
self.embedding_model = "all-MiniLM-L6-v2"
self.embedding_engine = "SentenceTransformers"

# If we have a customized embedding model, we'll use it.
for model in self.config.models:
if model.type == "embedding":
if model.type == "embeddings":
self.embedding_model = model.model
assert model.engine in get_embedding_provider_names()
self.embedding_engine = model.engine
Expand Down
2 changes: 1 addition & 1 deletion nemoguardrails/rails/llm/llmrails.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _init_llms(self):
# to search for the main model config.

for llm_config in self.config.models:
if llm_config.type == "embedding":
if llm_config.type == "embeddings":
if llm_config.engine not in get_embedding_provider_names():
raise Exception(f"Unknown embedding engine: {llm_config.engine}")
else:
Expand Down

0 comments on commit acb49c4

Please sign in to comment.