-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd1d11f
commit 804a7db
Showing
11 changed files
with
766 additions
and
736 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
docs/core_docs/docs/integrations/document_loaders/web_loaders/oracleai.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
hide_table_of_contents: true | ||
--- | ||
|
||
# Oracle AI | ||
|
||
This example goes over how to load documents using Oracle AI Vector Search. | ||
|
||
## Setup | ||
|
||
You'll need to install the [oracledb](https://www.npmjs.com/package/oracledb) package: | ||
|
||
```bash npm2yarn | ||
npm install @langchain/community @langchain/core oracledb | ||
``` | ||
|
||
## Usage | ||
|
||
### Connect to Oracle Database | ||
You'll need to provide the username, password, hostname and service_name: | ||
|
||
```typescript | ||
import oracledb from 'oracledb'; | ||
|
||
let connection: oracledb.Connection; | ||
|
||
// Replace the placeholders with your information | ||
const username = "<username>"; | ||
const password = "<password>"; | ||
const dsn = "<hostname>/<service_name>"; | ||
|
||
try { | ||
connection = await oracledb.getConnection({ | ||
user: username, | ||
password:password, | ||
connectString: dsn | ||
}); | ||
console.log("Connection Successful"); | ||
} catch (err) { | ||
console.error('Connection failed:', err); | ||
throw err; | ||
} | ||
``` | ||
|
||
### Load Documents | ||
As for loading documents, you have 3 options: | ||
- Loading a local file. | ||
- Loading from a local directory. | ||
- Loading from the Oracle Database. | ||
|
||
When loading from the Oracle Database, you must provide the table's name, owner's name, and the name of the column to load. Optionally, you can provide extra column names to be included in the returned documents' metadata: | ||
|
||
```typescript | ||
import { OracleDocLoader, OracleLoadFromType } from "@langchain/community/document_loaders/web/oracleai"; | ||
|
||
/* | ||
// Loading a local file (replace <filepath> with the path of the file you want to load.) | ||
const loader = new OracleDocLoader(connection, <filepath>, OracleLoadFromType.FILE); | ||
// Loading from a local directory (replace <dirpath> with the path of the directory you want to load from.) | ||
const loader = new OracleDocLoader(connection, <dirpath>, OracleLoadFromType.DIR); | ||
*/ | ||
|
||
// Loading from Oracle Database table (replace the placeholders with your information, optionally add a [metadata_cols] parameter to include columns as metadata.) | ||
const loader = new OracleDocLoader(connection, <tablename>, OracleLoadFromType.TABLE, <owner_name>, <colname>); | ||
|
||
// Load the docs | ||
const docs = loader.load(); | ||
console.log("Number of docs loaded:", docs.length); | ||
console.log("Document-0:", docs[0].page_content); // content | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import oracledb from 'oracledb'; | ||
import { OracleDocLoader, OracleLoadFromType } from "@langchain/community/document_loaders/web/oracleai"; | ||
|
||
let connection: oracledb.Connection; | ||
|
||
// Replace the placeholders with your information | ||
const username = "<username>"; | ||
const pwd = "<password>"; | ||
const dsn = "<hostname>/<service_name>"; | ||
|
||
try { | ||
connection = await oracledb.getConnection({ | ||
user: username, | ||
password: pwd, | ||
connectString: dsn | ||
}); | ||
console.log("Connection Successful"); | ||
} catch (err) { | ||
console.error('Connection failed:', err); | ||
throw err; | ||
} | ||
|
||
// Loading a local file (replace <filepath> with the path of the file you want to load.) | ||
const loader = new OracleDocLoader(connection, "src/document_loaders/example_data/bitcoin.pdf", OracleLoadFromType.FILE); | ||
|
||
/* | ||
// Loading from a local directory (replace <dirpath> with the path of the directory you want to load from.) | ||
const loader = new OracleDocLoader(connection, <dirpath>, OracleLoadFromType.DIR); | ||
// Loading from Oracle Database table (replace the placeholders with your information, optionally add a [metadata_cols] parameter to include columns as metadata.) | ||
const loader = new OracleDocLoader(connection, <tablename>, OracleLoadFromType.TABLE, <owner_name>, <colname>); | ||
*/ | ||
|
||
// Load the docs | ||
const docs = loader.load(); | ||
console.log("Number of docs loaded:", docs.length); | ||
console.log("Document-0:", docs[0].page_content); // content | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 17 additions & 14 deletions
31
libs/langchain-community/src/document_loaders/tests/example_data/oracleai/example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta name="keywords"> | ||
<meta> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="keywords" /> | ||
<meta /> | ||
<title>Sample HTML Page</title> | ||
</head> | ||
<body> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>Welcome to My Sample HTML Page</h1> | ||
<h1>Welcome to My Sample HTML Page</h1> | ||
</header> | ||
|
||
<main> | ||
<h2>Introduction</h2> | ||
<p>This is a small HTML file with a header, main content section, and a footer.</p> | ||
<p>Feel free to modify and experiment with the code!</p> | ||
<h2>Introduction</h2> | ||
<p> | ||
This is a small HTML file with a header, main content section, and a | ||
footer. | ||
</p> | ||
<p>Feel free to modify and experiment with the code!</p> | ||
</main> | ||
|
||
<footer> | ||
<p>Footer Content - © 2024</p> | ||
<p>Footer Content - © 2024</p> | ||
</footer> | ||
</body> | ||
</html> | ||
</body> | ||
</html> |
Oops, something went wrong.