@harperfast/template-react-studio 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/harper-best-practices/AGENTS.md +258 -0
- package/.agents/skills/harper-best-practices/SKILL.md +88 -0
- package/.agents/skills/harper-best-practices/rules/adding-tables-with-schemas.md +40 -0
- package/.agents/skills/harper-best-practices/rules/automatic-apis.md +34 -0
- package/.agents/skills/harper-best-practices/rules/caching.md +46 -0
- package/.agents/skills/harper-best-practices/rules/checking-authentication.md +165 -0
- package/.agents/skills/harper-best-practices/rules/custom-resources.md +35 -0
- package/.agents/skills/harper-best-practices/rules/defining-relationships.md +33 -0
- package/.agents/skills/harper-best-practices/rules/deploying-to-harper-fabric.md +24 -0
- package/.agents/skills/harper-best-practices/rules/extending-tables.md +37 -0
- package/.agents/skills/harper-best-practices/rules/handling-binary-data.md +43 -0
- package/.agents/skills/harper-best-practices/rules/programmatic-table-requests.md +39 -0
- package/.agents/skills/harper-best-practices/rules/querying-rest-apis.md +22 -0
- package/.agents/skills/harper-best-practices/rules/real-time-apps.md +37 -0
- package/.agents/skills/harper-best-practices/rules/serving-web-content.md +34 -0
- package/.agents/skills/harper-best-practices/rules/typescript-type-stripping.md +32 -0
- package/.agents/skills/harper-best-practices/rules/using-blob-datatype.md +36 -0
- package/.agents/skills/harper-best-practices/rules/vector-indexing.md +152 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/resources/README.md +3 -3
- package/schemas/README.md +2 -2
- package/skills-lock.json +10 -0
- package/AGENTS.md +0 -22
- package/skills/adding-tables-with-schemas.md +0 -34
- package/skills/automatic-apis.md +0 -53
- package/skills/automatic-rest-apis.md +0 -41
- package/skills/caching.md +0 -113
- package/skills/checking-authentication.md +0 -281
- package/skills/custom-resources.md +0 -86
- package/skills/defining-relationships.md +0 -71
- package/skills/deploying-to-harper-fabric.md +0 -20
- package/skills/extending-tables.md +0 -70
- package/skills/handling-binary-data.md +0 -67
- package/skills/programmatic-table-requests.md +0 -185
- package/skills/querying-rest-apis.md +0 -69
- package/skills/real-time-apps.md +0 -75
- package/skills/serving-web-content.md +0 -82
- package/skills/typescript-type-stripping.md +0 -47
- package/skills/using-blob-datatype.md +0 -131
- package/skills/vector-indexing.md +0 -215
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
# Blob (Binary Large Objects)
|
|
2
|
-
|
|
3
|
-
Harper supports **Blobs** — binary large objects for storing unstructured or large binary data — with integrated streaming support and efficient storage. Blobs are ideal for media files, documents, and any data where size or throughput makes standard JSON fields impractical.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## What Are Blobs
|
|
8
|
-
|
|
9
|
-
Blobs extend the native JavaScript `Blob` type and allow you to store **binary or arbitrary data** inside Harper tables. The blob reference is stored in the record, while the blob’s contents are streamed to and from storage.
|
|
10
|
-
|
|
11
|
-
- Designed for binary data such as images, audio, and documents
|
|
12
|
-
- Supports streaming reads and writes
|
|
13
|
-
- Blob data is stored separately from record attributes
|
|
14
|
-
- Optimized for large payloads
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Defining Blob Fields
|
|
19
|
-
|
|
20
|
-
Declare a blob field using the `Blob` type in your schema:
|
|
21
|
-
|
|
22
|
-
```graphql
|
|
23
|
-
type MyTable @table {
|
|
24
|
-
id: ID @primaryKey
|
|
25
|
-
data: Blob
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Any record written to this field will store a reference to the blob’s contents.
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## Creating and Storing Blobs
|
|
34
|
-
|
|
35
|
-
### Creating a Blob from a Buffer
|
|
36
|
-
|
|
37
|
-
```js
|
|
38
|
-
const blob = createBlob(largeBuffer);
|
|
39
|
-
await MyTable.put({ id: 'my-record', data: blob });
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
- `createBlob()` returns a blob reference
|
|
43
|
-
- Data is streamed to storage asynchronously
|
|
44
|
-
- Records may be committed before the blob finishes writing
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
### Creating a Blob from a Stream
|
|
49
|
-
|
|
50
|
-
```js
|
|
51
|
-
const blob = createBlob(stream);
|
|
52
|
-
await MyTable.put({ id: 'streamed-record', data: blob });
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Streaming allows large data to be written without loading it fully into memory.
|
|
56
|
-
|
|
57
|
-
---
|
|
58
|
-
|
|
59
|
-
## Reading Blob Data
|
|
60
|
-
|
|
61
|
-
Retrieve a record and read its blob contents:
|
|
62
|
-
|
|
63
|
-
```js
|
|
64
|
-
const record = await MyTable.get('my-record');
|
|
65
|
-
const buffer = await record.data.bytes();
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
Blob objects also support streaming interfaces for large reads.
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## Blob Attributes and Events
|
|
73
|
-
|
|
74
|
-
### Size
|
|
75
|
-
|
|
76
|
-
The blob size may not be immediately available when streaming:
|
|
77
|
-
|
|
78
|
-
```js
|
|
79
|
-
if (blob.size === undefined) {
|
|
80
|
-
blob.on('size', size => {
|
|
81
|
-
console.log('Blob size:', size);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
|
-
### saveBeforeCommit
|
|
89
|
-
|
|
90
|
-
Blobs are not atomic while streaming. To ensure the blob is fully written before committing the record:
|
|
91
|
-
|
|
92
|
-
```js
|
|
93
|
-
const blob = createBlob(stream, { saveBeforeCommit: true });
|
|
94
|
-
await MyTable.put({ id: 'safe-record', data: blob });
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
## Error Handling
|
|
100
|
-
|
|
101
|
-
Handle streaming errors by attaching an error listener:
|
|
102
|
-
|
|
103
|
-
```js
|
|
104
|
-
blob.on('error', () => {
|
|
105
|
-
MyTable.invalidate('my-record');
|
|
106
|
-
});
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
This prevents partially written blobs from being used.
|
|
110
|
-
|
|
111
|
-
---
|
|
112
|
-
|
|
113
|
-
## Automatic Coercion
|
|
114
|
-
|
|
115
|
-
When a field is defined as `Blob`, assigning a string or buffer automatically converts it into a blob when using `put`, `patch`, or `publish`.
|
|
116
|
-
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
## Related Skill
|
|
120
|
-
|
|
121
|
-
- [Handling Binary Data with Blobs](handling-binary-data.md) How to store and serve binary data like images or MP3s using the Blob data type.
|
|
122
|
-
|
|
123
|
-
---
|
|
124
|
-
|
|
125
|
-
## Summary
|
|
126
|
-
|
|
127
|
-
- Blobs store large or binary data efficiently
|
|
128
|
-
- Blob fields reference streamed content
|
|
129
|
-
- Supports buffered and streamed writes
|
|
130
|
-
- Optional write-before-commit behavior
|
|
131
|
-
- Integrates seamlessly with Harper tables
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
# Vector Indexing
|
|
2
|
-
|
|
3
|
-
Harper supports **vector indexing** on array attributes, enabling efficient similarity search over high-dimensional vector data. This is essential for AI-powered features such as semantic search, recommendations, and embeddings-based retrieval.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## What Is Vector Indexing
|
|
8
|
-
|
|
9
|
-
Vector indexing organizes numeric vectors so that Harper can efficiently find records that are closest to a given query vector using a distance metric such as cosine similarity or Euclidean distance.
|
|
10
|
-
|
|
11
|
-
Unlike traditional indexes that rely on exact matches, vector indexes enable **nearest-neighbor search** across high-dimensional spaces, making them ideal for embeddings and machine learning workloads.
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Enabling a Vector Index
|
|
16
|
-
|
|
17
|
-
Vector indexes are defined using the `@indexed` directive on numeric array attributes.
|
|
18
|
-
|
|
19
|
-
```graphql
|
|
20
|
-
type Product @table {
|
|
21
|
-
id: Long @primaryKey
|
|
22
|
-
name: String
|
|
23
|
-
description: String
|
|
24
|
-
textEmbeddings: [Float] @indexed(type: "HNSW")
|
|
25
|
-
price: Float
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
- `type: "HNSW"` enables Harper’s vector index using the HNSW algorithm
|
|
30
|
-
- The indexed field must be an array of numeric values
|
|
31
|
-
- Vector indexes are stored and maintained automatically
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## Querying with a Vector Index
|
|
36
|
-
|
|
37
|
-
### Search Vectors with sort
|
|
38
|
-
|
|
39
|
-
Once defined, vector indexes can be used by specifying a `sort` configuration with a target vector. To view the similarity of a result to a given query vector, use the `$distance` attribute in the `select` clause.
|
|
40
|
-
|
|
41
|
-
```js
|
|
42
|
-
const results = Product.search({
|
|
43
|
-
select: ['name', 'description', 'price', '$distance'],
|
|
44
|
-
sort: {
|
|
45
|
-
attribute: 'textEmbeddings',
|
|
46
|
-
target: searchVector,
|
|
47
|
-
},
|
|
48
|
-
limit: 5,
|
|
49
|
-
});
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
- `attribute` is the vector index attribute
|
|
53
|
-
- `target` is the vector to compare against
|
|
54
|
-
- `searchVector` is the embedding to compare against
|
|
55
|
-
- Results are ordered by similarity
|
|
56
|
-
- Vector search can be combined with filters and limits
|
|
57
|
-
- The `$distance` attribute in the `select` (optional) returns the distance between the result and the query vector
|
|
58
|
-
|
|
59
|
-
### Search Vectors limited by distance
|
|
60
|
-
|
|
61
|
-
Vector indexes results can be limited by distance using the `conditions` clause. In the following example, results are returned that are less than 0.1 similar to the query vector.
|
|
62
|
-
The `conditions` clause can be combined with `sort` and `limit` and the `comparator` can be any of the following: `lt`, `lte`, `gt`, `gte`, `between`.
|
|
63
|
-
|
|
64
|
-
```js
|
|
65
|
-
const results = Product.search({
|
|
66
|
-
select: ['name', 'description', 'price', '$distance'],
|
|
67
|
-
conditions: {
|
|
68
|
-
attribute: 'textEmbeddings',
|
|
69
|
-
comparator: 'lt',
|
|
70
|
-
value: 0.1, // '0.1' is the similarity threshold
|
|
71
|
-
target: searchVector,
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
- `attribute` is the vector index attribute
|
|
77
|
-
- `comparator` is the comparison operator (`lt`, `lte`, `gt`, `gte`, `between` are accepted)
|
|
78
|
-
- `value` is the threshold value
|
|
79
|
-
- `target` is the vector to compare against
|
|
80
|
-
- `searchVector` is the embedding to compare against
|
|
81
|
-
- Vector search can be combined with filters, sort, and limits
|
|
82
|
-
- The `$distance` attribute in the `select` (optional) returns the distance between the result and the query vector
|
|
83
|
-
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
## Vector Index Options
|
|
87
|
-
|
|
88
|
-
Additional tuning options can be provided on the `@indexed` directive:
|
|
89
|
-
|
|
90
|
-
| Option | Description |
|
|
91
|
-
| ---------------------- | ------------------------------------------- |
|
|
92
|
-
| `distance` | Similarity metric (`cosine` or `euclidean`) |
|
|
93
|
-
| `efConstruction` | Index build quality vs performance |
|
|
94
|
-
| `M` | Graph connectivity per HNSW layer |
|
|
95
|
-
| `optimizeRouting` | Improves routing efficiency |
|
|
96
|
-
| `efSearchConstruction` | Search breadth during queries |
|
|
97
|
-
|
|
98
|
-
These options allow fine-tuning for performance and recall tradeoffs.
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## How to Generate and Search Vector Embeddings
|
|
103
|
-
|
|
104
|
-
Here is a full example that generates embeddings for a set of products and then searches for similar products using vector indexes. The following example shows how to generate embeddings using OpenAI or Ollama.
|
|
105
|
-
|
|
106
|
-
```js
|
|
107
|
-
import { Ollama } from 'ollama';
|
|
108
|
-
const ollama = new Ollama({ host: 'http://127.0.0.1:11434' });
|
|
109
|
-
// The name of the ollama embedding model
|
|
110
|
-
const OLLAMA_EMBEDDING_MODEL = 'nomic-embed-text';
|
|
111
|
-
|
|
112
|
-
const { Product } = tables;
|
|
113
|
-
|
|
114
|
-
import OpenAI from 'openai';
|
|
115
|
-
const openai = new OpenAI();
|
|
116
|
-
// the name of the OpenAI embedding model
|
|
117
|
-
const OPENAI_EMBEDDING_MODEL = 'text-embedding-3-small';
|
|
118
|
-
|
|
119
|
-
const SIMILARITY_THRESHOLD = 0.5;
|
|
120
|
-
|
|
121
|
-
export class ProductSearch extends Resource {
|
|
122
|
-
// based on env variable we choose the appropriate embedding generator
|
|
123
|
-
generateEmbedding = process.env.EMBEDDING_GENERATOR === 'ollama'
|
|
124
|
-
? this._generateOllamaEmbedding
|
|
125
|
-
: this._generateOpenAIEmbedding;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Executes a search query using a generated text embedding and returns the matching products.
|
|
129
|
-
*
|
|
130
|
-
* @param {Object} data - The input data for the request.
|
|
131
|
-
* @param {string} data.prompt - The prompt to generate the text embedding from.
|
|
132
|
-
* @return {Promise<Array>} Returns a promise that resolves to an array of products matching the conditions,
|
|
133
|
-
* including fields: name, description, price, and $distance.
|
|
134
|
-
*/
|
|
135
|
-
async post(data) {
|
|
136
|
-
const embedding = await this.generateEmbedding(data.prompt);
|
|
137
|
-
|
|
138
|
-
return await Product.search({
|
|
139
|
-
select: ['name', 'description', 'price', '$distance'],
|
|
140
|
-
conditions: {
|
|
141
|
-
attribute: 'textEmbeddings',
|
|
142
|
-
comparator: 'lt',
|
|
143
|
-
value: SIMILARITY_THRESHOLD,
|
|
144
|
-
target: embedding[0],
|
|
145
|
-
},
|
|
146
|
-
limit: 5,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Generates an embedding using the Ollama API.
|
|
152
|
-
*
|
|
153
|
-
* @param {string} promptData - The input data for which the embedding is to be generated.
|
|
154
|
-
* @return {Promise<number[][]>} A promise that resolves to the generated embedding as an array of numbers.
|
|
155
|
-
*/
|
|
156
|
-
async _generateOllamaEmbedding(promptData) {
|
|
157
|
-
const embedding = await ollama.embed({
|
|
158
|
-
model: OLLAMA_EMBEDDING_MODEL,
|
|
159
|
-
input: promptData,
|
|
160
|
-
});
|
|
161
|
-
return embedding?.embeddings;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Generates OpenAI embeddings based on the given prompt data.
|
|
166
|
-
*
|
|
167
|
-
* @param {string} promptData - The input data used for generating the embedding.
|
|
168
|
-
* @return {Promise<number[][]>} A promise that resolves to an array of embeddings, where each embedding is an array of floats.
|
|
169
|
-
*/
|
|
170
|
-
async _generateOpenAIEmbedding(promptData) {
|
|
171
|
-
const embedding = await openai.embeddings.create({
|
|
172
|
-
model: OPENAI_EMBEDDING_MODEL,
|
|
173
|
-
input: promptData,
|
|
174
|
-
encoding_format: 'float',
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
let embeddings = [];
|
|
178
|
-
embedding.data.forEach((embeddingData) => {
|
|
179
|
-
embeddings.push(embeddingData.embedding);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
return embeddings;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
Sample request to the `ProductSearch` resource which prompts to find "shorts for the gym":
|
|
188
|
-
|
|
189
|
-
```bash
|
|
190
|
-
curl -X POST "http://localhost:9926/ProductSearch/" \
|
|
191
|
-
-H "accept: \
|
|
192
|
-
-H "Content-Type: application/json" \
|
|
193
|
-
-H "Authorization: Basic <YOUR_AUTH>" \
|
|
194
|
-
-d '{"prompt": "shorts for the gym"}'
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
---
|
|
198
|
-
|
|
199
|
-
## When to Use Vector Indexing
|
|
200
|
-
|
|
201
|
-
Vector indexing is ideal when:
|
|
202
|
-
|
|
203
|
-
- Storing embedding vectors from ML models
|
|
204
|
-
- Performing semantic or similarity-based search
|
|
205
|
-
- Working with high-dimensional numeric data
|
|
206
|
-
- Exact-match indexes are insufficient
|
|
207
|
-
|
|
208
|
-
---
|
|
209
|
-
|
|
210
|
-
## Summary
|
|
211
|
-
|
|
212
|
-
- Vector indexing enables fast similarity search on numeric arrays
|
|
213
|
-
- Defined using `@indexed(type: "HNSW")`
|
|
214
|
-
- Queried using a target vector in search sorting
|
|
215
|
-
- Tunable for performance and accuracy
|