Skip to content

Commit 26035bb

Browse files
committed
add vector column/index doc, update singlestore doc to rm mysql-core
1 parent 676a708 commit 26035bb

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

src/content/docs/column-types/singlestore.mdx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,62 @@ CREATE TABLE `table` (
560560

561561
## ---
562562

563+
### vector
564+
565+
<Section>
566+
```typescript
567+
import { singlestoreTable, vector } from "drizzle-orm/singlestore-core";
568+
569+
const table = singlestoreTable('table', {
570+
embedding: vector("embedding", { dimensions: 10 }),
571+
});
572+
```
573+
574+
```sql
575+
CREATE TABLE `table` (
576+
`embedding` vector(10)
577+
);
578+
```
579+
</Section>
580+
581+
You can specify `elementType` in order to change what element type the vector
582+
consists of. This can be one of `I8`, `I16`, `I32`, `I64`, `F32`, or `F64`
583+
584+
<Section>
585+
```typescript
586+
import { singlestoreTable, vector } from "drizzle-orm/singlestore-core";
587+
588+
const table = singlestoreTable('table', {
589+
embedding: vector("embedding", { dimensions: 10, elementType: 'I8' }),
590+
});
591+
```
592+
593+
```sql
594+
CREATE TABLE `table` (
595+
`embedding` vector(10, 'I8')
596+
);
597+
```
598+
</Section>
599+
600+
###### Helper functions
601+
602+
There are two helper functions useful for vector search queries in SingleStore:
603+
604+
<Section>
605+
```typescript
606+
import { dotProduct, euclideanDistance } from 'drizzle-orm/singlestore-core/expressions';
607+
608+
euclideanDistance(table.column, [3, 1, 2]);
609+
dotProduct(table.column, [3, 1, 2]);
610+
```
611+
```sql
612+
table.column <-> '[3, 1, 2]'
613+
table.column <*> '[3, 1, 2]`
614+
```
615+
</Section>
616+
617+
## ---
618+
563619
### Customizing data type
564620
565621
Every column builder has a `.$type()` method, which allows you to customize the data type of the column. This is useful, for example, with unknown or branded types.

src/content/docs/indexes-constraints.mdx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ index('name')
11181118
</Tab>
11191119
<Tab>
11201120
<Section>
1121-
```typescript copy {9-10}
1121+
```typescript copy {8-9}
11221122
import { int, text, index, uniqueIndex, singlestoreTable } from "drizzle-orm/singlestore-core";
11231123

11241124
export const user = singlestoreTable("user", {
@@ -1139,5 +1139,30 @@ index('name')
11391139
CREATE UNIQUE INDEX `email_idx` ON `user` (`email`);
11401140
```
11411141
</Section>
1142+
1143+
SingleStore also supports indexes on vector columns:
1144+
1145+
<Section>
1146+
```typescript copy {8-9}
1147+
import { int, singlestoreTable, vector, vectorIndex } from "drizzle-orm/singlestore-core";
1148+
1149+
export const embeddings = singlestoreTable("embeddings", {
1150+
id: int("id").primaryKey().autoincrement(),
1151+
embedding: vector("embedding", { dimensions: 10 }).notNull(),
1152+
embedding2: vector("embedding2", { dimensions: 10 }).notNull(),
1153+
}, (table) => [
1154+
vectorIndex("vIdx1").on(table.embedding),
1155+
vectorIndex("vIdx2", "IVF_PQ").on(table.embedding2).metricType("EUCLIDEAN_DISTANCE").nbits(16),
1156+
]);
1157+
```
1158+
```sql {5-6}
1159+
CREATE TABLE `embeddings` (
1160+
...
1161+
);
1162+
1163+
ALTER TABLE `embeddings` ADD VECTOR INDEX `vIdx1` (`embedding`) INDEX_OPTIONS '{"index_type":"AUTO"}';
1164+
ALTER TABLE `embeddings` ADD VECTOR INDEX `vIdx2` (`embedding2`) INDEX_OPTIONS '{"index_type":"IVF_PQ","metric_type":"EUCLIDEAN_DISTANCE","nbits":16}';
1165+
```
1166+
</Section>
11421167
</Tab>
11431168
</Tabs>

0 commit comments

Comments
 (0)