> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Johnsnowlabs 集成

> 通过开源 johnsnowlabs 库，获取 johnsnowlabs 企业级 NLP 库的访问权限，该生态系统包含超过 21.000 个企业级 NLP 模型，支持 200 多种语言。 所有 24.000+ 模型，请参阅 John Snow Labs Model Models Hub

通过开源 `johnsnowlabs` 库，获取 [johnsnowlabs](https://www.johnsnowlabs.com/) 企业级 NLP 库的访问权限，该生态系统包含超过 21.000 个企业级 NLP 模型，支持 200 多种语言。
所有 24.000+ 模型，请参阅 [John Snow Labs Model Models Hub](https://nlp.johnsnowlabs.com/models)

## 安装和设置

```bash pip theme={null}
pip install johnsnowlabs
```

```bash uv theme={null}
uv add johnsnowlabs
```

要 \[安装企业级功能]\([https://nlp.johnsnowlabs.com/docs/en/jsl/install\_licensed\_quick](https://nlp.johnsnowlabs.com/docs/en/jsl/install_licensed_quick), 运行：

```python theme={null}
# for more details see https://nlp.johnsnowlabs.com/docs/en/jsl/install_licensed_quick
nlp.install()
```

您可以使用 `gpu`、`cpu`、`apple_silicon`、`aarch` 基于优化的二进制文件嵌入您的查询和文档。
默认情况下使用 CPU 二进制文件。
启动会话后，您必须重启您的笔记本才能在 GPU 或 CPU 之间切换，否则更改将不会生效。

## 使用 CPU 嵌入查询：

```python theme={null}
document = "foo bar"
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert')
output = embedding.embed_query(document)
```

## 使用 GPU 嵌入查询：

```python theme={null}
document = "foo bar"
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','gpu')
output = embedding.embed_query(document)
```

## 使用 apple silicon (M1,M2,等..) 嵌入查询：

```python theme={null}
documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','apple_silicon')
output = embedding.embed_query(document)
```

## 使用 AARCH 嵌入查询：

```python theme={null}
documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','aarch')
output = embedding.embed_query(document)
```

## 使用 CPU 嵌入文档：

```python theme={null}
documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','gpu')
output = embedding.embed_documents(documents)
```

## 使用 GPU 嵌入文档：

```python theme={null}
documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','gpu')
output = embedding.embed_documents(documents)
```

## 使用 apple silicon (M1,M2,等..) 嵌入文档：

````python theme={null}
```python
documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','apple_silicon')
output = embedding.embed_documents(documents)
````

## Embed Document with AARCH:

````python theme={null}
```python
documents = ["foo bar", 'bar foo']
embedding = JohnSnowLabsEmbeddings('embed_sentence.bert','aarch')
output = embedding.embed_documents(documents)
````

模型通过 [nlp.load](https://nlp.johnsnowlabs.com/docs/en/jsl/load_api) 加载，而 spark 会话通过 [nlp.start()](https://nlp.johnsnowlabs.com/docs/en/jsl/start-a-sparksession) 在底层启动。

※ 重要提示：在您之前的输出中占位符集不正确。缺少的 ID：\['0']; 预期之外的额外 ID：\[]。请再次翻译全文，保持每个占位符（六边形括号 + 数字）的原位，且仅出现一次。

***

> 官方原文：[src/oss/python/integrations/providers/johnsnowlabs.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/providers/johnsnowlabs.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.