forked from run-llama/LlamaIndexTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
npm:postgres
(run-llama#1248)
- Loading branch information
Showing
17 changed files
with
225 additions
and
42 deletions.
There are no files selected for viewing
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,8 @@ | ||
--- | ||
"@llamaindex/core": patch | ||
"llamaindex": patch | ||
"@llamaindex/core-e2e": patch | ||
"pg-vector-store": patch | ||
--- | ||
|
||
feat: support `npm:postgres` |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# neon template | ||
PGHOST= | ||
PGDATABASE= | ||
PGUSER= | ||
PGPASSWORD= | ||
ENDPOINT_ID= |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
examples/pg-vector-store/load-docs.ts → examples/vector-store/pg/load-docs.ts
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-disable turbo/no-undeclared-env-vars */ | ||
import dotenv from "dotenv"; | ||
import { Document, PGVectorStore, VectorStoreQueryMode } from "llamaindex"; | ||
import postgres from "postgres"; | ||
|
||
dotenv.config(); | ||
|
||
const { PGHOST, PGDATABASE, PGUSER, ENDPOINT_ID } = process.env; | ||
const PGPASSWORD = decodeURIComponent(process.env.PGPASSWORD!); | ||
|
||
const sql = postgres({ | ||
host: PGHOST, | ||
database: PGDATABASE, | ||
username: PGUSER, | ||
password: PGPASSWORD, | ||
port: 5432, | ||
ssl: "require", | ||
connection: { | ||
options: `project=${ENDPOINT_ID}`, | ||
}, | ||
}); | ||
|
||
await sql`CREATE EXTENSION IF NOT EXISTS vector`; | ||
|
||
const vectorStore = new PGVectorStore({ | ||
dimensions: 3, | ||
client: sql, | ||
}); | ||
|
||
await vectorStore.add([ | ||
new Document({ | ||
text: "hello, world", | ||
embedding: [1, 2, 3], | ||
}), | ||
]); | ||
|
||
const results = await vectorStore.query({ | ||
mode: VectorStoreQueryMode.DEFAULT, | ||
similarityTopK: 1, | ||
queryEmbedding: [1, 2, 3], | ||
}); | ||
|
||
console.log("result", results); | ||
|
||
await sql.end(); |
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,5 @@ | ||
{ | ||
"name": "pg-vector-store", | ||
"type": "module", | ||
"private": true | ||
} |
File renamed without changes.
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,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"types": ["node"], | ||
"skipLibCheck": true | ||
}, | ||
"include": ["./**/*.ts"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* should compatible with npm:pg and npm:postgres | ||
*/ | ||
export interface IsomorphicDB { | ||
query: (sql: string, params?: any[]) => Promise<any[]>; | ||
// begin will wrap the multiple queries in a transaction | ||
begin: <T>(fn: (query: IsomorphicDB["query"]) => Promise<T>) => Promise<T>; | ||
|
||
// event handler | ||
connect: () => Promise<void>; | ||
close: () => Promise<void>; | ||
onCloseEvent: (listener: () => void) => void; | ||
} |
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
Oops, something went wrong.