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

# OracleSummary 集成

> 使用 LangChain JavaScript 与 OracleSummary 工具集成。

<Tip>
  **兼容性**：仅适用于 Node.js。
</Tip>

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

本指南演示了如何使用 Oracle AI Vector Search LangChain 集成中的 `OracleSummary` 来生成文档摘要。

> **为什么需要摘要功能？**
> 摘要是将长文档压缩为便于检索的内容（预览、元数据或浓缩上下文）的一种实用方法，同时保持数据治理和操作保障。

如果您刚开始使用 Oracle 数据库，可以考虑探索[免费的 Oracle 26 AI](https://www.oracle.com/database/free/#resources)。关于用户管理的背景信息，请参考官方的 [Oracle 指南](https://docs.oracle.com/en/database/oracle/oracle-database/26/dbseg/configuring-privilege-and-role-authorization.html#GUID-16473474-7F47-4E40-A592-01836E7D911C)。

## 概述

### 集成详情

| 类               | 包                                                                                        |  本地 | [Python 支持](https://python.langchain.com/docs/integrations/tools/oracleai) |
| :-------------- | :--------------------------------------------------------------------------------------- | :-: | :------------------------------------------------------------------------: |
| `OracleSummary` | [`@oracle/langchain-oracledb`](https://www.npmjs.com/package/@oracle/langchain-oracledb) |  ✅  |                                      ✅                                     |

## 设置

要访问 OracleSummary，请安装 `@oracle/langchain-oracledb` 辅助工具（以及 `@langchain/core`），并确保您的环境满足 [Oracle 数据库驱动](https://node-oracledb.readthedocs.io/en/latest/) 的先决条件。

### 凭据

为拥有摘要配置的 Oracle 用户设置凭据（或使用密钥管理器）：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export ORACLE_USER=testuser
export ORACLE_PASSWORD=testuser
export ORACLE_DSN="localhost:1521/free"
```

如果您计划调用第三方提供商，如 OCI Generative AI 或 Hugging Face，请首先在 Oracle 数据库内创建凭据（例如 `OCI_CRED`、`HF_CRED`），使用 [Oracle AI Vector Search 指南](https://www.oracle.com/pls/topic/lookup?ctx=dblatest\&id=GUID-EC9DDB58-6A15-4B36-BA66-ECBA20D2CE57) 中记录的 PL/SQL 辅助工具。

### 安装

<CodeGroup>
  ```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  npm install @oracle/langchain-oracledb @langchain/core
  ```

  ```bash yarn theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  yarn add @oracle/langchain-oracledb @langchain/core
  ```

  ```bash pnpm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pnpm add @oracle/langchain-oracledb @langchain/core
  ```
</CodeGroup>

## 实例化工具

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import oracledb from "oracledb";
import { OracleSummary } from "@oracle/langchain-oracledb";

const connection = await oracledb.getConnection({
  user: process.env.ORACLE_USER,
  password: process.env.ORACLE_PASSWORD,
  connectionString: process.env.ORACLE_DSN,
});

const summary = new OracleSummary(
  connection,
  {
    provider: "database",
    glevel: "S",
    numParagraphs: 1,
    language: "english",
  },
  process.env.HTTP_PROXY, // 可选
);
```

第三个构造函数参数是一个可选的代理字符串。仅当出站请求必须通过 HTTP 代理（例如，调用 Hugging Face 端点）时才提供。

## 使用数据库内模型进行文本摘要

直接在 Oracle 数据库中运行 ONNX 摘要模型，将数据保留在与事务工作负载相同的主机上。

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const result = await summary.getSummary(
  "Oracle Database combines relational and vector workloads so you can build secure RAG pipelines.",
);

console.log(result); // => 简洁的摘要文本
```

## 使用托管提供商

将 `provider` 参数切换为通过 [OCI Generative AI](https://docs.oracle.com/en-us/iaas/Content/generative-ai/home.htm) 或 Hugging Face 路由摘要请求。提供您在 Oracle 数据库中注册的凭据名称，如果需要，还需提供代理字符串。

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const ociSummary = new OracleSummary(
  connection,
  {
    provider: "ocigenai",
    credential_name: "OCI_CRED",
    url: "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/summarizeText",
    model: "cohere.command",
  },
  process.env.HTTP_PROXY,
);

const hfSummary = new OracleSummary(connection, {
  provider: "huggingface",
  credential_name: "HF_CRED",
  url: "https://api-inference.huggingface.co/models/",
  model: "facebook/bart-large-cnn",
  wait_for_model: "true",
});
```

## 与 LangChain 工具链式集成

您可以将 `OracleSummary` 包装在自定义的 LangChain 工具或可运行对象中，以便与代理工具调用集成。

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { tool } from "@langchain/core/tools";
import { z } from "zod";

const summarizeTool = tool(
  async ({ text }: { text: string }) => summary.getSummary(text),
  {
    name: "oracle_summary",
    description: "摘要 Oracle 来源的文档。",
    schema: z.object({
      text: z.string().describe("要摘要的完整文本"),
    }),
  },
);

const toolSummary = await summarizeTool.invoke({ text });
```

## 后续步骤

* 使用 [`OracleDocLoader`](/oss/javascript/integrations/document_loaders/file_loaders/oracleai) 加载内容
* 使用 [`OracleTextSplitter`](/oss/javascript/integrations/document_loaders/file_loaders/oracleai#chunk-documents) 进行分块和规范化
* 使用 [`OracleEmbeddings`](/oss/javascript/integrations/embeddings/oracleai) 生成嵌入，并将其存储在 [`OracleVS`](/oss/javascript/integrations/vectorstores/oracleai) 中

***

## API 参考

有关 `OracleSummary` 所有参数和返回类型的详细文档，请参阅 [Oracle LangChain Oracle DB 仓库](https://github.com/oracle/langchain-oracle/tree/main/libs/js/langchain-oracledb)。

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\javascript\integrations\tools\oracleai.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
