-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Oracle Database Document Loader and Parser #7251
Open
Minjun1Kim
wants to merge
5
commits into
langchain-ai:main
Choose a base branch
from
AshwinM1523:oracle-doc-loader
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
52c2083
Create ParseOracleDocMetadata
AshwinM1523 14c4df9
Created OracleDocReader class
asadCoder fc84e27
Created OracleDocLoader class and UTs for loading files and dirs
AhmadHakim2004 bd1d11f
Implemented loading tables
Minjun1Kim 804a7db
Added docs and reformatted the code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,9 +39,11 @@ | |
"binary-extensions": "^2.2.0", | ||
"expr-eval": "^2.0.2", | ||
"flat": "^5.0.2", | ||
"htmlparser2": "^9.1.0", | ||
"js-yaml": "^4.1.0", | ||
"langchain": ">=0.2.3 <0.3.0 || >=0.3.4 <0.4.0", | ||
"langsmith": "^0.2.0", | ||
"oracledb": "^6.7.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should not be direct dependencies |
||
"uuid": "^10.0.0", | ||
"zod": "^3.22.3", | ||
"zod-to-json-schema": "^3.22.5" | ||
|
@@ -120,6 +122,7 @@ | |
"@types/jsonwebtoken": "^9", | ||
"@types/lodash": "^4", | ||
"@types/mozilla-readability": "^0.2.1", | ||
"@types/oracledb": "^6", | ||
"@types/pdf-parse": "^1.1.1", | ||
"@types/pg": "^8.11.0", | ||
"@types/pg-copy-streams": "^1.2.2", | ||
|
@@ -2791,6 +2794,15 @@ | |
"import": "./document_loaders/web/notionapi.js", | ||
"require": "./document_loaders/web/notionapi.cjs" | ||
}, | ||
"./document_loaders/web/oracleai": { | ||
"types": { | ||
"import": "./document_loaders/web/oracleai.d.ts", | ||
"require": "./document_loaders/web/oracleai.d.cts", | ||
"default": "./document_loaders/web/oracleai.d.ts" | ||
}, | ||
"import": "./document_loaders/web/oracleai.js", | ||
"require": "./document_loaders/web/oracleai.cjs" | ||
}, | ||
"./document_loaders/web/pdf": { | ||
"types": { | ||
"import": "./document_loaders/web/pdf.d.ts", | ||
|
@@ -4025,6 +4037,10 @@ | |
"document_loaders/web/notionapi.js", | ||
"document_loaders/web/notionapi.d.ts", | ||
"document_loaders/web/notionapi.d.cts", | ||
"document_loaders/web/oracleai.cjs", | ||
"document_loaders/web/oracleai.js", | ||
"document_loaders/web/oracleai.d.ts", | ||
"document_loaders/web/oracleai.d.cts", | ||
"document_loaders/web/pdf.cjs", | ||
"document_loaders/web/pdf.js", | ||
"document_loaders/web/pdf.d.ts", | ||
|
Binary file added
BIN
+71.9 KB
...hain-community/src/document_loaders/tests/example_data/oracleai/Jacob_Lee_Resume_2023.pdf
Binary file not shown.
28 changes: 28 additions & 0 deletions
28
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 |
---|---|---|
@@ -0,0 +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 /> | ||
<title>Sample HTML Page</title> | ||
</head> | ||
<body> | ||
<header> | ||
<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> | ||
</main> | ||
|
||
<footer> | ||
<p>Footer Content - © 2024</p> | ||
</footer> | ||
</body> | ||
</html> |
4 changes: 4 additions & 0 deletions
4
libs/langchain-community/src/document_loaders/tests/example_data/oracleai/example.txt
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,4 @@ | ||
Foo | ||
Bar | ||
Baz | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run
yarn format