> ## 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.

# Oracle AI vector search generate summary 集成

> 使用 LangChain Python 集成 Oracle AI 向量搜索生成摘要工具。

Oracle AI 数据库支持通过**语义**（语义学）而非关键词查询数据的 AI 工作负载。它将**非结构化内容语义搜索**与**业务数据关系过滤**结合在单一系统中——因此您可以在不引入单独的向量数据库的情况下构建检索工作流（如 RAG），并避免将数据分散在多个平台。

本指南演示如何使用 `OracleSummary` 从 Oracle AI 向量搜索 LangChain 集成生成文档摘要。

> **为何选择摘要？**
> 摘要是将长文档压缩为检索友好内容（预览、元数据或精简上下文）的实用方法，同时将治理和操作保证紧密保持在数据附近。

如果您刚开始使用 Oracle 数据库，请考虑探索 [免费的 Oracle 26 AI](https://www.oracle.com/database/free/#resources)。有关端到端设置演示，请参阅 [Oracle AI 向量搜索演示笔记本](https://github.com/langchain-ai/langchain/blob/v0.3/cookbook/oracleai_demo.ipynb)。有关用户管理的背景信息，请参考官方 [Oracle 指南](https://docs.oracle.com/en/database/oracle/oracle-database/19/admqs/administering-user-accounts-and-security.html#GUID-36B21D72-1BBB-46C9-A0C9-F0D2A8591B8D)。

### 前置条件

安装 `langchain-oracledb`。`python-oracledb` 驱动程序将作为依赖项自动安装。

```bash pip theme={null}
pip install -qU langchain-oracledb
```

```bash uv theme={null}
uv add langchain-oracledb
```

### 连接到 Oracle 数据库

以下示例代码将展示如何连接到 Oracle 数据库。默认情况下，python-oracledb 以“Thin”模式运行，直接连接到 Oracle 数据库。此模式无需 Oracle 客户端库。然而，当 python-oracledb 使用它们时，会提供一些附加功能。当使用 Oracle 客户端库时，python-oracledb 被称为“Thick”模式。两种模式都具有支持 Python 数据库 API v2.0 规范的全面功能。有关每种模式下支持的功能的更多信息，请参阅以下 [指南](https://python-oracledb.readthedocs.io/en/latest/user_guide/appendix_a.html#featuresummary)。如果您无法使用 Thin 模式，可能需要切换到 Thick 模式。

```python theme={null}
import oracledb

# Please update with your username, password, hostname, port and service_name
username = "<username>"
password = "<password>"
dsn = "<hostname>:<port>/<service_name>"

connection = oracledb.connect(user=username, password=password, dsn=dsn)
print("Connection successful!")
```

### 生成摘要

Oracle AI 向量搜索 LangChain 库提供了一套用于文档摘要的 API。它支持多种摘要提供者，如 Database、OCIGENAI、HuggingFace 等，允许用户选择最适合其需求的提供者。要利用这些功能，用户必须按指定配置摘要参数。有关这些参数的详细信息，请参阅 [Oracle AI 向量搜索指南](https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/dbms_vector_chain1.html#GUID-EC9DDB58-6A15-4B36-BA66-ECBA20D2CE57)。

***注意：*** 如果用户希望使用 Oracle 内部默认提供者以外的第三方摘要生成提供者，可能需要设置代理：'database'。如果您没有代理，请在实例化 OracleSummary 时移除代理参数。

```python theme={null}
# proxy to be used when we instantiate summary and embedder object
proxy = "<proxy>"
```

以下示例代码将展示如何生成摘要：

```python theme={null}
from langchain_oracledb.utilities.oracleai import OracleSummary
from langchain_core.documents import Document

"""
# using 'ocigenai' provider
summary_params = {
    "provider": "ocigenai",
    "credential_name": "OCI_CRED",
    "url": "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/summarizeText",
    "model": "cohere.command",
}

# using 'huggingface' provider
summary_params = {
    "provider": "huggingface",
    "credential_name": "HF_CRED",
    "url": "https://api-inference.huggingface.co/models/",
    "model": "facebook/bart-large-cnn",
    "wait_for_model": "true"
}
"""

# using 'database' provider
summary_params = {
    "provider": "database",
    "glevel": "S",
    "numParagraphs": 1,
    "language": "english",
}

# get the summary instance
# Remove proxy if not required
summ = OracleSummary(conn=conn, params=summary_params, proxy=proxy)
summary = summ.get_summary(
    "In the heart of the forest, "
    + "a lone fox ventured out at dusk, seeking a lost treasure. "
    + "With each step, memories flooded back, guiding its path. "
    + "As the moon rose high, illuminating the night, the fox unearthed "
    + "not gold, but a forgotten friendship, worth more than any riches."
)

print(f"Summary generated by OracleSummary: {summary}")
```

### 端到端演示

请参考我们的完整演示指南 [Oracle AI 向量搜索端到端演示指南](https://github.com/langchain-ai/langchain/blob/v0.3/cookbook/oracleai_demo.ipynb)，以借助 Oracle AI 向量搜索构建端到端 RAG 管道。

***

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


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