-
Notifications
You must be signed in to change notification settings - Fork 21
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
8ca62e0
commit 1d4d68f
Showing
2 changed files
with
35 additions
and
8 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 |
---|---|---|
@@ -1,7 +1,24 @@ | ||
import { Pinecone } from '@pinecone-database/pinecone' | ||
import { CreateIndexOptions, Index, Pinecone } from '@pinecone-database/pinecone' | ||
import { PineconeConflictError } from '@pinecone-database/pinecone/dist/errors' | ||
|
||
const pc = new Pinecone() | ||
|
||
export async function get_or_create_index(opts: CreateIndexOptions): Promise<Index> { | ||
try { | ||
await pc.createIndex(opts) | ||
} catch (e) { | ||
console.log( | ||
'Error creating new index with name ' + | ||
opts.name + | ||
'. This is expected if the index already exists. The error is as follows: ' + | ||
(e as Error).message, | ||
) | ||
} | ||
|
||
const index: Index = await pc.index(opts.name) | ||
return index | ||
} | ||
|
||
export async function get_index(name: string) { | ||
return await pc.index(name) | ||
} |
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