langchain.embeddings.spacy_embeddings.SpacyEmbeddings¶

class langchain.embeddings.spacy_embeddings.SpacyEmbeddings(*, nlp: Any = None)[source]¶

Bases: BaseModel, Embeddings

Embeddings by SpaCy models.

It only supports the ‘en_core_web_sm’ model.

nlp¶

The Spacy model loaded into memory.

Type

Any

embed_documents(texts

List[str]) -> List[List[float]]: Generates embeddings for a list of documents.

embed_query(text

str) -> List[float]: Generates an embedding for a single piece of text.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param nlp: Any = None¶
async aembed_documents(texts: List[str]) List[List[float]][source]¶

Asynchronously generates embeddings for a list of documents. This method is not implemented and raises a NotImplementedError.

Parameters

texts (List[str]) – The documents to generate embeddings for.

Raises

NotImplementedError – This method is not implemented.

async aembed_query(text: str) List[float][source]¶

Asynchronously generates an embedding for a single piece of text. This method is not implemented and raises a NotImplementedError.

Parameters

text (str) – The text to generate an embedding for.

Raises

NotImplementedError – This method is not implemented.

embed_documents(texts: List[str]) List[List[float]][source]¶

Generates embeddings for a list of documents.

Parameters

texts (List[str]) – The documents to generate embeddings for.

Returns

A list of embeddings, one for each document.

embed_query(text: str) List[float][source]¶

Generates an embedding for a single piece of text.

Parameters

text (str) – The text to generate an embedding for.

Returns

The embedding for the text.

validator validate_environment  »  all fields[source]¶

Validates that the Spacy package and the ‘en_core_web_sm’ model are installed.

Parameters

values (Dict) – The values provided to the class constructor.

Returns

The validated values.

Raises
  • ValueError – If the Spacy package or the ‘en_core_web_sm’

  • model are not installed. –

model Config[source]¶

Bases: object

Configuration for this pydantic object.

extra = 'forbid'¶

Examples using SpacyEmbeddings¶