Skip to content

Latest commit

 

History

History
196 lines (91 loc) · 4.54 KB

nemoguardrails.embeddings.basic.md

File metadata and controls

196 lines (91 loc) · 4.54 KB

module nemoguardrails.embeddings.basic


function init_embedding_model

init_embedding_model(
    embedding_model: str,
    embedding_engine: str
) → EmbeddingModel

Initialize the embedding model.


class BasicEmbeddingsIndex

Basic implementation of an embeddings index.

It uses sentence-transformers/all-MiniLM-L6-v2 to compute the embeddings. It uses Annoy to perform the search.

method BasicEmbeddingsIndex.__init__

__init__(embedding_model=None, embedding_engine=None, index=None)

property BasicEmbeddingsIndex.embedding_size


property BasicEmbeddingsIndex.embeddings


property BasicEmbeddingsIndex.embeddings_index


method BasicEmbeddingsIndex.add_item

add_item(item: nemoguardrails.embeddings.index.IndexItem)

Add a single item to the index.


method BasicEmbeddingsIndex.add_items

add_items(items: List[nemoguardrails.embeddings.index.IndexItem])

Add multiple items to the index at once.


method BasicEmbeddingsIndex.build

build()

Builds the Annoy index.


method BasicEmbeddingsIndex.search

search(
    text: str,
    max_results: int = 20
) → List[nemoguardrails.embeddings.index.IndexItem]

Search the closest max_results items.


class SentenceTransformerEmbeddingModel

Embedding model using sentence-transformers.

method SentenceTransformerEmbeddingModel.__init__

__init__(embedding_model: str)

method SentenceTransformerEmbeddingModel.encode

encode(documents: List[str]) → List[List[float]]

class OpenAIEmbeddingModel

Embedding model using OpenAI API.

method OpenAIEmbeddingModel.__init__

__init__(embedding_model: str)

method OpenAIEmbeddingModel.encode

encode(documents: List[str]) → List[List[float]]

Encode a list of documents into embeddings.