Skip to content

Commit ebee3fc

Browse files
authored
Update README example for new OpenAI version (#54)
1 parent ea0a91f commit ebee3fc

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Vectra
2-
Vectra is a local vector database for Node.js with features similar to [Pinecone](https://www.pinecone.io/) or [Qdrant](https://qdrant.tech/) but built using local files. Each Vectra index is a folder on disk. There's an `index.json` file in the folder that contains all the vectors for the index along with any indexed metadata. When you create an index you can specify which metadata properties to index and only those fields will be stored in the `index.json` file. All of the other metadata for an item will be stored on disk in a separate file keyed by a GUID.
2+
3+
Vectra is a local vector database for Node.js with features similar to [Pinecone](https://www.pinecone.io/) or [Qdrant](https://qdrant.tech/) but built using local files. Each Vectra index is a folder on disk. There's an `index.json` file in the folder that contains all the vectors for the index along with any indexed metadata. When you create an index you can specify which metadata properties to index and only those fields will be stored in the `index.json` file. All of the other metadata for an item will be stored on disk in a separate file keyed by a GUID.
34

45
When queryng Vectra you'll be able to use the same subset of [Mongo DB query operators](https://www.mongodb.com/docs/manual/reference/operator/query/) that Pinecone supports and the results will be returned sorted by simularity. Every item in the index will first be filtered by metadata and then ranked for simularity. Even though every item is evaluated its all in memory so it should by nearly instantanious. Likely 1ms - 2ms for even a rather large index. Smaller indexes should be <1ms.
56

@@ -8,9 +9,10 @@ Keep in mind that your entire Vectra index is loaded into memory so it's not wel
89
Pinecone style namespaces aren't directly supported but you could easily mimic them by creating a separate Vectra index (and folder) for each namespace.
910

1011
## Other Language Bindings
12+
1113
This repo contains the TypeScript/JavaScript binding for Vectra but other language bindings are being created. Since Vectra is file based, any language binding can be used to read or write a Vectra index. That means you can build a Vectra index using JS and then read it using Python.
1214

13-
- [vectra-py](https://github.com/BMS-geodev/vectra-py) - Python version of Vectra.
15+
- [vectra-py](https://github.com/BMS-geodev/vectra-py) - Python version of Vectra.
1416

1517
## Installation
1618

@@ -31,34 +33,32 @@ const index = new LocalIndex(path.join(__dirname, '..', 'index'));
3133
Next, from inside an async function, create your index:
3234

3335
```typescript
34-
if (!await index.isIndexCreated()) {
36+
if (!(await index.isIndexCreated())) {
3537
await index.createIndex();
3638
}
3739
```
3840

3941
Add some items to your index:
4042

4143
```typescript
42-
import { OpenAIApi, Configuration } from 'openai';
44+
import { OpenAI } from 'openai';
4345

44-
const configuration = new Configuration({
46+
const openai = new OpenAI({
4547
apiKey: `<YOUR_KEY>`,
4648
});
4749

48-
const api = new OpenAIApi(configuration);
49-
5050
async function getVector(text: string) {
51-
const response = await api.createEmbedding({
51+
const response = await openai.embeddings.create({
5252
'model': 'text-embedding-ada-002',
5353
'input': text,
5454
});
55-
return response.data.data[0].embedding;
55+
return response.data[0].embedding;
5656
}
5757

5858
async function addItem(text: string) {
5959
await index.insertItem({
6060
vector: await getVector(text),
61-
metadata: { text }
61+
metadata: { text },
6262
});
6363
}
6464

0 commit comments

Comments
 (0)