-
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.
feat: add preview vector index client (#710)
* feat: adding preview vector index client Co-authored-by: Michael Landis <[email protected]> Co-authored-by: Chris Price <[email protected]>
- Loading branch information
1 parent
3ccbfff
commit f1721cc
Showing
28 changed files
with
66,830 additions
and
4,820 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
examples/web/vector-index/doc-example-files/doc-examples-web-apis.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
async function example_API_CreateIndex(vectorClient: PreviewVectorClient) { | ||
const result = await vectorClient.createIndex('test-index'); | ||
if (result instanceof CreateIndex.Success) { | ||
console.log("Index 'test-index' created"); | ||
} else if (result instanceof CreateIndex.AlreadyExists) { | ||
console.log("Index 'test-index' already exists"); | ||
} else if (result instanceof CreateIndex.Error) { | ||
throw new Error( | ||
`An error occurred while attempting to create index 'test-index': ${result.errorCode()}: ${result.toString()}` | ||
); | ||
} | ||
} | ||
|
||
async function example_API_ListIndexes(vectorClient: PreviewVectorClient) { | ||
const result = await vectorClient.listIndexes(); | ||
if (result instanceof ListIndexes.Success) { | ||
console.log( | ||
`Indexes:\n${result | ||
.getIndexNames() | ||
.join('\n')}\n\n` | ||
); | ||
} else if (result instanceof ListIndexes.Error) { | ||
throw new Error(`An error occurred while attempting to list caches: ${result.errorCode()}: ${result.toString()}`); | ||
} | ||
} | ||
|
||
async function example_API_DeleteIndex(vectorClient: PreviewVectorClient) { | ||
const result = await vectorClient.deleteIndex("test-index") | ||
if (result instanceof DeleteIndex.Success) { | ||
console.log("Index 'test-index' deleted"); | ||
} else if (result instanceof DeleteIndex.Error) { | ||
throw new Error( | ||
`An error occurred while attempting to delete index 'test-index': ${result.errorCode()}: ${result.toString()}` | ||
); | ||
} | ||
} |
Oops, something went wrong.