Skip to content

[SingleStore] Add Vector column/index doc, fix SingleStore imports #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/content/docs/column-types/singlestore.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,62 @@ CREATE TABLE `table` (

## ---

### vector

<Section>
```typescript
import { singlestoreTable, vector } from "drizzle-orm/singlestore-core";

const table = singlestoreTable('table', {
embedding: vector('embedding', { dimensions: 10 }),
});
```

```sql
CREATE TABLE `table` (
`embedding` vector(10, F32)
);
```
</Section>

You can specify `elementType` in order to change what element type the vector
consists of. This can be one of `I8`, `I16`, `I32`, `I64`, `F32`, or `F64`

<Section>
```typescript
import { singlestoreTable, vector } from "drizzle-orm/singlestore-core";

const table = singlestoreTable('table', {
embedding: vector('embedding', { dimensions: 10, elementType: 'I8' }),
});
```

```sql
CREATE TABLE `table` (
`embedding` vector(10, I8)
);
```
</Section>

###### Helper functions

There are two helper functions useful for vector search queries in SingleStore:

<Section>
```typescript
import { dotProduct, euclideanDistance } from 'drizzle-orm/singlestore-core/expressions';

euclideanDistance(table.column, [3, 1, 2]);
dotProduct(table.column, [3, 1, 2]);
```
```sql
table.column <-> '[3, 1, 2]'
table.column <*> '[3, 1, 2]`
```
</Section>

## ---

### Customizing data type

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.
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/guides/_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
["empty-array-default-value", "Empty array as a default value"],
["update-many-with-different-value", "Update many with different value for each row"],
["unique-case-insensitive-email", "Unique and Case-Insensitive Email Handling"],
["vector-similarity-search", "Vector similarity search with pgvector extension"],
["vector-similarity-search", "Vector similarity search"],
["postgresql-full-text-search", "PostgreSQL full-text search"],
["d1-http-with-drizzle-kit", "Cloudflare D1 HTTP API with Drizzle Kit"],
["point-datatype-psql", "Point datatype in PostgreSQL"],
Expand Down
Loading