You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/06-concepts/02-models.md
+55-10Lines changed: 55 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ fields:
18
18
employees: List<Employee>
19
19
```
20
20
21
-
Supported types are [bool](https://api.dart.dev/dart-core/bool-class.html), [int](https://api.dart.dev/dart-core/int-class.html), [double](https://api.dart.dev/dart-core/double-class.html), [String](https://api.dart.dev/dart-core/String-class.html), [Duration](https://api.dart.dev/dart-core/Duration-class.html), [DateTime](https://api.dart.dev/dart-core/DateTime-class.html), [ByteData](https://api.dart.dev/dart-typed_data/ByteData-class.html), [UuidValue](https://pub.dev/documentation/uuid/latest/uuid_value/UuidValue-class.html), [Uri](https://api.dart.dev/dart-core/Uri-class.html), [BigInt](https://api.dart.dev/dart-core/BigInt-class.html), [Vector](#vector-fields) and other serializable [classes](#class), [exceptions](#exception) and [enums](#enum). You can also use [List](https://api.dart.dev/dart-core/List-class.html)s, [Map](https://api.dart.dev/dart-core/Map-class.html)s and [Set](https://api.dart.dev/dart-core/Set-class.html)s of the supported types, just make sure to specify the types. All supported types can also be used inside [Record](https://api.dart.dev/dart-core/Record-class.html)s. Null safety is supported. Once your classes are generated, you can use them as parameters or return types to endpoint methods.
21
+
Supported types are [bool](https://api.dart.dev/dart-core/bool-class.html), [int](https://api.dart.dev/dart-core/int-class.html), [double](https://api.dart.dev/dart-core/double-class.html), [String](https://api.dart.dev/dart-core/String-class.html), [Duration](https://api.dart.dev/dart-core/Duration-class.html), [DateTime](https://api.dart.dev/dart-core/DateTime-class.html), [ByteData](https://api.dart.dev/dart-typed_data/ByteData-class.html), [UuidValue](https://pub.dev/documentation/uuid/latest/uuid_value/UuidValue-class.html), [Uri](https://api.dart.dev/dart-core/Uri-class.html), [BigInt](https://api.dart.dev/dart-core/BigInt-class.html), [Vector](#vector), [HalfVector](#halfvector), [SparseVector](#sparsevector), [Bit](#bit) and other serializable [classes](#class), [exceptions](#exception) and [enums](#enum). You can also use [List](https://api.dart.dev/dart-core/List-class.html)s, [Map](https://api.dart.dev/dart-core/Map-class.html)s and [Set](https://api.dart.dev/dart-core/Set-class.html)s of the supported types, just make sure to specify the types. All supported types can also be used inside [Record](https://api.dart.dev/dart-core/Record-class.html)s. Null safety is supported. Once your classes are generated, you can use them as parameters or return types to endpoint methods.
22
22
23
23
### Limiting visibility of a generated class
24
24
@@ -135,7 +135,25 @@ fields:
135
135
136
136
## Vector fields
137
137
138
-
The `Vector` type is used for storing high-dimensional vectors, which are specially useful for similarity search operations.
138
+
Vector types are used for storing high-dimensional vectors, which are especially useful for similarity search operations.
139
+
140
+
When specifying vector types, the dimension is required between parentheses (e.g., `Vector(1536)`). Common dimensions include:
141
+
142
+
- 1536 (OpenAI embeddings)
143
+
- 768 (many sentence transformers)
144
+
- 384 (smaller models)
145
+
146
+
All vector types support specialized distance operations for similarity search and filtering. See the [Vector distance operators](database/filter#vector-distance-operators) section for details.
147
+
148
+
To ensure optimal performance with vector similarity searches, consider creating specialized vector indexes on your vector fields. See the [Vector indexes](database/indexing#vector-indexes) section for more details.
149
+
150
+
:::info
151
+
The usage of Vector fields requires the pgvector PostgreSQL extension to be installed, which comes by default on new Serverpod projects. To upgrade an existing project, see the [Upgrading to pgvector support](../upgrading/upgrade-to-pgvector) guide.
152
+
:::
153
+
154
+
### Vector
155
+
156
+
The `Vector` type stores full-precision floating-point vectors for general-purpose embeddings.
139
157
140
158
```yaml
141
159
class: Document
@@ -151,17 +169,44 @@ fields:
151
169
embedding: Vector(1536)
152
170
```
153
171
154
-
The number in parentheses specifies the vector dimensions. Common dimensions include:
172
+
### HalfVector
155
173
156
-
- 1536 (OpenAI embeddings)
157
-
- 768 (many sentence transformers)
158
-
- 384 (smaller models)
174
+
The `HalfVector` type uses half-precision (16-bit) floating-point numbers, providing memory savings with acceptable precision loss for several applications.
175
+
176
+
```yaml
177
+
class: Document
178
+
table: document
179
+
fields:
180
+
content: String
181
+
### Half-precision embedding for memory efficiency
182
+
embedding: HalfVector(1536)
183
+
```
159
184
160
-
Vector fields support specialized distance operations for similarity search and filtering. See the [Vector distance operators](database/filter#vector-distance-operators) section for details.
185
+
### SparseVector
161
186
162
-
:::info
163
-
The usage of Vector fields requires the pgvector PostgreSQL extension to be installed, which comes by default on new Serverpod projects. To upgrade an existing project, see the [Upgrading to pgvector support](../upgrading/upgrade-to-pgvector) guide.
164
-
:::
187
+
The `SparseVector` type efficiently stores sparse vectors where most values are zero, which is ideal for high-dimensional data with few non-zero elements.
188
+
189
+
```yaml
190
+
class: Document
191
+
table: document
192
+
fields:
193
+
content: String
194
+
### Sparse vector for keyword-based embeddings
195
+
keywords: SparseVector(10000)
196
+
```
197
+
198
+
### Bit
199
+
200
+
The `Bit` type stores binary vectors where each element is 0 or 1, offering maximum memory efficiency for binary embeddings.
Copy file name to clipboardExpand all lines: docs/06-concepts/06-database/04-indexing.md
+30-4Lines changed: 30 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -65,10 +65,10 @@ If no type is specified the default is `btree`. All [PostgreSQL index types](htt
65
65
66
66
### Vector indexes
67
67
68
-
To enhance the performance of vector similarity search, it is possible to create specialized vector indexes on `Vector` fields. Serverpod supports both `HNSW` and `IVFFLAT` index types with full parameter specification.
68
+
To enhance the performance of vector similarity search, it is possible to create specialized vector indexes on vector fields (`Vector`, `HalfVector`, `SparseVector`, `Bit`). Serverpod supports both `hnsw` and `ivfflat` index types with full parameter specification.
69
69
70
70
:::info
71
-
Each vector index can only be created on a single `Vector` field. It is not possible to create a vector index on multiple fields of any kind.
71
+
Each vector index can only be created on a single vector field. It is not possible to create a vector index on multiple fields of any kind.
72
72
:::
73
73
74
74
#### HNSW indexes
@@ -81,6 +81,8 @@ table: document
81
81
fields:
82
82
content: String
83
83
embedding: Vector(1536)
84
+
keywords: SparseVector(10000)
85
+
hash: Bit(256)
84
86
indexes:
85
87
document_embedding_hnsw_idx:
86
88
fields: embedding
@@ -89,11 +91,26 @@ indexes:
89
91
parameters:
90
92
m: 16
91
93
ef_construction: 64
94
+
document_keywords_idx:
95
+
fields: keywords
96
+
type: hnsw
97
+
distanceFunction: innerProduct
98
+
parameters:
99
+
m: 16
100
+
ef_construction: 64
101
+
document_hash_idx:
102
+
fields: hash
103
+
type: hnsw
104
+
distanceFunction: hamming
105
+
parameters:
106
+
m: 16
107
+
ef_construction: 64
92
108
```
93
109
94
110
Available HNSW parameters:
95
-
- `m`: Maximum number of bi-directional links for each node (default: 16)
96
-
- `efConstruction`: Size of the dynamic candidate list (default: 64)
111
+
112
+
- `m`: Maximum number of bidirectional links for each node (default: 16)
113
+
- `ef_construction`: Size of the dynamic candidate list (default: 64)
97
114
98
115
#### IVFFLAT indexes
99
116
@@ -115,6 +132,7 @@ indexes:
115
132
```
116
133
117
134
Available IVFFLAT parameters:
135
+
118
136
- `lists`: Number of inverted lists (default: 100)
Different vector types have specific limitations when creating indexes:
152
+
153
+
- **SparseVector**: Can only use HNSW indexes (IVFFLAT is not supported).
154
+
- **HalfVector**: When using IVFFLAT indexes, the L1 distance function is not supported.
155
+
- **Bit**: Only supports `hamming` (default) and `jaccard` distance functions.
130
156
131
157
:::tip
132
158
If more than one distance function is going to be frequently used on the same vector field, consider creating one index for each distance function to ensure optimal performance.
0 commit comments