Skip to content

Commit 0d5f166

Browse files
authored
Suggested changes to getting started (#6)
... including set dimension to 5.
1 parent 81ac84b commit 0d5f166

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

README.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,40 @@
77
```typescript
88
import { AstraDB } from "@datastax/astra-db-ts";
99

10-
const { TOKEN, DATABASE_ID, REGION, COLLECTION_NAME, ENDPOINT } = process.env;
10+
async function main() {
1111

12-
const astraDb = new AstraDB(TOKEN, DATABASE_ID, REGION);
13-
// or...
14-
// const astraDb = new AstraDB(TOKEN, ENDPOINT);
12+
const ASTRA_DB_API_ENDPOINT = process.env['ASTRA_DB_API_ENDPOINT'];
13+
const ASTRA_DB_APPLICATION_TOKEN = process.env['ASTRA_DB_APPLICATION_TOKEN'];
1514

16-
// Create a collection
17-
const collection = await astraDb.collection(COLLECTION_NAME);
15+
const db = new AstraDB(ASTRA_DB_APPLICATION_TOKEN, ASTRA_DB_API_ENDPOINT);
1816

19-
// Return the number of documents in the collection
20-
const results = await collection.countDocuments();
17+
// Create a vector collection
18+
await db.createCollection("vector_5_collection", { vector: { dimension: 5, metric: "cosine" } });
19+
const collection = await db.collection("vector_5_collection");
20+
21+
const documents = [
22+
{
23+
"_id": "1",
24+
"text": "ChatGPT integrated sneakers that talk to you",
25+
"$vector": [0.1, 0.15, 0.3, 0.12, 0.05],
26+
},
27+
{
28+
"_id": "2",
29+
"text": "An AI quilt to help you sleep forever",
30+
"$vector": [0.45, 0.09, 0.01, 0.2, 0.11],
31+
},
32+
{
33+
"_id": "3",
34+
"text": "Vision Vector Frame - A deep learning display that controls your mood",
35+
"$vector": [0.1, 0.05, 0.08, 0.3, 0.6],
36+
}
37+
];
38+
await collection.insertMany(documents);
39+
40+
// Return the number of documents in the collection
41+
const results = await collection.countDocuments();
42+
console.log(results);
43+
}
44+
45+
main().catch(console.error);
2146
```

0 commit comments

Comments
 (0)