@bridgerust/embex 0.1.13 → 0.1.15
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/README.md +70 -97
- package/bin/embex.js +0 -0
- package/bun.lockb +0 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/native.d.ts +138 -0
- package/dist/native.js +579 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +26 -0
- package/dist/src/tests/integration/adapters.test.d.ts +13 -0
- package/dist/src/tests/integration/adapters.test.d.ts.map +1 -0
- package/dist/src/tests/integration/adapters.test.js +372 -0
- package/dist/src/tests/integration/aggregations.test.d.ts +6 -0
- package/dist/src/tests/integration/aggregations.test.d.ts.map +1 -0
- package/dist/src/tests/integration/aggregations.test.js +96 -0
- package/dist/src/tests/integration/api_parity.test.d.ts +6 -0
- package/dist/src/tests/integration/api_parity.test.d.ts.map +1 -0
- package/dist/src/tests/integration/api_parity.test.js +99 -0
- package/dist/src/tests/integration/batch.test.d.ts +2 -0
- package/dist/src/tests/integration/batch.test.d.ts.map +1 -0
- package/dist/src/tests/integration/batch.test.js +53 -0
- package/dist/src/tests/integration/errors.test.d.ts +6 -0
- package/dist/src/tests/integration/errors.test.d.ts.map +1 -0
- package/dist/src/tests/integration/errors.test.js +133 -0
- package/dist/src/tests/integration/features.test.d.ts +2 -0
- package/dist/src/tests/integration/features.test.d.ts.map +1 -0
- package/dist/src/tests/integration/features.test.js +37 -0
- package/dist/src/tests/integration/filters.test.d.ts +6 -0
- package/dist/src/tests/integration/filters.test.d.ts.map +1 -0
- package/dist/src/tests/integration/filters.test.js +296 -0
- package/dist/src/tests/integration/metadata.test.d.ts +6 -0
- package/dist/src/tests/integration/metadata.test.d.ts.map +1 -0
- package/dist/src/tests/integration/metadata.test.js +167 -0
- package/dist/src/tests/integration/migrations.test.d.ts +2 -0
- package/dist/src/tests/integration/migrations.test.d.ts.map +1 -0
- package/dist/src/tests/integration/migrations.test.js +55 -0
- package/dist/src/tests/integration/pooling.test.d.ts +6 -0
- package/dist/src/tests/integration/pooling.test.d.ts.map +1 -0
- package/dist/src/tests/integration/pooling.test.js +56 -0
- package/dist/src/tests/integration/search.test.d.ts +2 -0
- package/dist/src/tests/integration/search.test.d.ts.map +1 -0
- package/dist/src/tests/integration/search.test.js +37 -0
- package/dist/src/tests/integration/streaming.test.d.ts +2 -0
- package/dist/src/tests/integration/streaming.test.d.ts.map +1 -0
- package/dist/src/tests/integration/streaming.test.js +42 -0
- package/dist/src/tests/unit/basic.test.d.ts +2 -0
- package/dist/src/tests/unit/basic.test.d.ts.map +1 -0
- package/dist/src/tests/unit/basic.test.js +23 -0
- package/dist/src/tests/unit/errors.test.d.ts +2 -0
- package/dist/src/tests/unit/errors.test.d.ts.map +1 -0
- package/dist/src/tests/unit/errors.test.js +19 -0
- package/package.json +7 -6
- package/tsconfig.json +2 -0
package/README.md
CHANGED
|
@@ -1,139 +1,112 @@
|
|
|
1
1
|
# Embex (Node.js)
|
|
2
2
|
|
|
3
|
-
**The
|
|
3
|
+
**The fastest way to add vector search to your app.**
|
|
4
4
|
|
|
5
|
-
Embex is a
|
|
5
|
+
Embex is a universal vector database client that lets you start with zero setup and scale to production without rewriting code.
|
|
6
6
|
|
|
7
7
|
## 🚀 Features
|
|
8
8
|
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
9
|
+
- **Start Simple**: Use LanceDB (embedded) for zero-setup local development.
|
|
10
|
+
- **Unified API**: Switch to Qdrant, Pinecone, or Milvus just by changing the config.
|
|
11
|
+
- **Performance**: Powered by a shared Rust core with SIMD acceleration.
|
|
11
12
|
- **Type Safety**: Full TypeScript support.
|
|
12
13
|
|
|
13
14
|
## 📦 Installation
|
|
14
15
|
|
|
15
16
|
```bash
|
|
16
|
-
npm install @bridgerust/embex
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
yarn add @bridgerust/embex
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
bun add @bridgerust/embex
|
|
17
|
+
npm install @bridgerust/embex lancedb @xenova/transformers
|
|
25
18
|
```
|
|
26
19
|
|
|
27
20
|
## ⚡ Quick Start
|
|
28
21
|
|
|
29
|
-
|
|
22
|
+
Build semantic search in 5 minutes using **LanceDB** (embedded) and local embeddings. No API keys or Docker needed!
|
|
30
23
|
|
|
31
24
|
```typescript
|
|
32
|
-
import { EmbexClient } from "@bridgerust/embex";
|
|
25
|
+
import { EmbexClient, Vector } from "@bridgerust/embex";
|
|
26
|
+
import { pipeline } from "@xenova/transformers";
|
|
33
27
|
|
|
34
28
|
async function main() {
|
|
35
|
-
//
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
29
|
+
// 1. Setup Embedding Model
|
|
30
|
+
const generateEmbedding = await pipeline(
|
|
31
|
+
"feature-extraction",
|
|
32
|
+
"Xenova/all-MiniLM-L6-v2"
|
|
33
|
+
);
|
|
34
|
+
const embed = async (text: string) => {
|
|
35
|
+
const output = await generateEmbedding(text, {
|
|
36
|
+
pooling: "mean",
|
|
37
|
+
normalize: true,
|
|
38
|
+
});
|
|
39
|
+
return Array.from(output.data);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// 2. Initialize Client (uses LanceDB embedded)
|
|
43
|
+
const client = await EmbexClient.newAsync("lancedb://./data");
|
|
44
|
+
|
|
45
|
+
// 3. Create Collection (384 dimensions for MiniLM)
|
|
46
|
+
await client.createCollection("products", 384);
|
|
47
|
+
|
|
48
|
+
// 4. Insert Data
|
|
49
|
+
const documents = [
|
|
50
|
+
{ id: "1", text: "Apple iPhone 15", category: "electronics" },
|
|
51
|
+
{ id: "2", text: "Samsung Galaxy S24", category: "electronics" },
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const vectors: Vector[] = [];
|
|
55
|
+
for (const doc of documents) {
|
|
56
|
+
vectors.push({
|
|
57
|
+
id: doc.id,
|
|
58
|
+
vector: await embed(doc.text),
|
|
59
|
+
metadata: { text: doc.text },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
await client.insert("products", vectors);
|
|
64
|
+
|
|
65
|
+
// 5. Search
|
|
66
|
+
const query = "smartphone";
|
|
67
|
+
const results = await client.search({
|
|
68
|
+
collection_name: "products",
|
|
69
|
+
vector: await embed(query),
|
|
70
|
+
limit: 1,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
console.log(`Query: '${query}'`);
|
|
74
|
+
console.log(`Match: ${results[0].metadata.text}`);
|
|
54
75
|
}
|
|
55
76
|
|
|
56
77
|
main();
|
|
57
78
|
```
|
|
58
79
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
### All Provider Quick Starts
|
|
80
|
+
## 🗺️ Development → Production Roadmap
|
|
62
81
|
|
|
63
|
-
|
|
82
|
+
| Stage | Recommendation | Why? |
|
|
83
|
+
| :------------------ | :-------------------- | :---------------------------------- |
|
|
84
|
+
| **Day 1: Learning** | **LanceDB** | Embedded. Zero setup. Free. |
|
|
85
|
+
| **Week 2: Staging** | **Qdrant / Pinecone** | Managed cloud. Connection pooling. |
|
|
86
|
+
| **Month 1: Scale** | **Milvus** | Distributed. Billion-scale vectors. |
|
|
87
|
+
| **Anytime** | **PgVector** | You already use PostgreSQL. |
|
|
64
88
|
|
|
65
|
-
|
|
66
|
-
| ------------ | --------------- | ---------------------------------------------- |
|
|
67
|
-
| **LanceDB** | None (embedded) | `npx tsx examples/lancedb/node/quickstart.ts` |
|
|
68
|
-
| **Qdrant** | Docker server | `npx tsx examples/qdrant/node/quickstart.ts` |
|
|
69
|
-
| **Pinecone** | API key | `npx tsx examples/pinecone/node/quickstart.ts` |
|
|
70
|
-
| **Chroma** | Optional server | `npx tsx examples/chroma/node/quickstart.ts` |
|
|
89
|
+
## ☁️ Switch Provider (Zero Code Changes)
|
|
71
90
|
|
|
72
|
-
|
|
91
|
+
Ready for production? Just change the initialization line.
|
|
73
92
|
|
|
74
|
-
|
|
93
|
+
**From LanceDB (Dev):**
|
|
75
94
|
|
|
76
95
|
```typescript
|
|
77
|
-
const
|
|
78
|
-
.limit(10)
|
|
79
|
-
.filter({
|
|
80
|
-
course: "CS101"
|
|
81
|
-
})
|
|
82
|
-
.execute();
|
|
96
|
+
const client = await EmbexClient.newAsync("lancedb://./data");
|
|
83
97
|
```
|
|
84
98
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
To connect to managed services like Pinecone, Qdrant Cloud, or Zilliz (Milvus), simply provide your API key and endpoint URL.
|
|
99
|
+
**To Qdrant Cloud (Prod):**
|
|
88
100
|
|
|
89
101
|
```typescript
|
|
90
|
-
import { EmbexClient } from "@bridgerust/embex";
|
|
91
|
-
|
|
92
|
-
// Connect to Pinecone
|
|
93
102
|
const client = new EmbexClient(
|
|
94
|
-
"pinecone",
|
|
95
|
-
"https://index-name.svc.pinecone.io",
|
|
96
|
-
process.env.PINECONE_API_KEY
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
// Connect to Qdrant Cloud
|
|
100
|
-
const qdrantClient = new EmbexClient(
|
|
101
103
|
"qdrant",
|
|
102
|
-
"https://
|
|
104
|
+
"https://your-cluster.qdrant.io",
|
|
103
105
|
process.env.QDRANT_API_KEY
|
|
104
106
|
);
|
|
105
107
|
```
|
|
106
108
|
|
|
107
|
-
### Official Documentation & API Keys
|
|
108
|
-
|
|
109
|
-
Need help finding your API key? Check the official provider documentation:
|
|
110
|
-
|
|
111
|
-
- **Pinecone**: [Authentication & API Keys](https://docs.pinecone.io/guides/get-started/quickstart#2-get-an-api-key)
|
|
112
|
-
- **Qdrant**: [Cloud Authentication](https://qdrant.tech/documentation/cloud/authentication/)
|
|
113
|
-
- **Milvus (Zilliz)**: [Manage Credentials](https://docs.zilliz.com/docs/manage-api-keys)
|
|
114
|
-
- **Weaviate**: [Authentication](https://weaviate.io/developers/weaviate/configuration/authentication)
|
|
115
|
-
- **Chroma**: [Auth & Client Settings](https://docs.trychroma.com/guides#authentication)
|
|
116
|
-
|
|
117
|
-
## 🔌 Supported Providers
|
|
118
|
-
|
|
119
|
-
| Provider | Key | Async Init? |
|
|
120
|
-
| -------- | ---------- | ----------- |
|
|
121
|
-
| Qdrant | `qdrant` | No |
|
|
122
|
-
| Chroma | `chroma` | No |
|
|
123
|
-
| Pinecone | `pinecone` | No |
|
|
124
|
-
| Weaviate | `weaviate` | No |
|
|
125
|
-
| LanceDB | `lancedb` | **Yes** |
|
|
126
|
-
| Milvus | `milvus` | **Yes** |
|
|
127
|
-
| PgVector | `pgvector` | **Yes** |
|
|
128
|
-
|
|
129
|
-
## ⭐ Star Us
|
|
130
|
-
|
|
131
|
-
If you find Embex useful, please star the repository! It helps others discover the project.
|
|
132
|
-
|
|
133
|
-
[⭐ Star on GitHub](https://github.com/bridgerust/bridgerust)
|
|
134
|
-
|
|
135
109
|
## 🔗 Resources
|
|
136
110
|
|
|
137
|
-
- **
|
|
138
|
-
- **
|
|
139
|
-
- **Documentation**: [Full Docs](https://github.com/bridgerust/bridgerust/tree/main/bindings/node/%40bridgerust/embex)
|
|
111
|
+
- **Full Documentation**: [bridgerust.dev/embex](https://bridgerust.dev/embex/introduction)
|
|
112
|
+
- **GitHub**: [bridgerust/bridgerust](https://github.com/bridgerust/bridgerust)
|
package/bin/embex.js
CHANGED
|
File without changes
|
package/bun.lockb
CHANGED
|
Binary file
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src"), exports);
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export declare class Collection {
|
|
4
|
+
/** Insert points into the collection. */
|
|
5
|
+
insert(points: Array<Point>): Promise<void>
|
|
6
|
+
/** Search for similar vectors. */
|
|
7
|
+
query(vector: Array<number>, options?: SearchOptions | undefined | null): Promise<SearchResponse>
|
|
8
|
+
/**
|
|
9
|
+
* Search for similar vectors with direct parameters.
|
|
10
|
+
*
|
|
11
|
+
* @param vector - Query vector
|
|
12
|
+
* @param topK - Number of results to return (default: 10)
|
|
13
|
+
* @param filter - Optional metadata filter
|
|
14
|
+
* @param includeMetadata - Whether to include metadata (default: true)
|
|
15
|
+
* @param includeVector - Whether to include vectors (default: false)
|
|
16
|
+
*/
|
|
17
|
+
search(vector: Array<number>, topK?: number | undefined | null, filter?: any | undefined | null, includeMetadata?: boolean | undefined | null, includeVector?: boolean | undefined | null): Promise<SearchResponse>
|
|
18
|
+
/** Search using a builder pattern. */
|
|
19
|
+
buildSearch(vector: Array<number>): SearchBuilder
|
|
20
|
+
/** Query using a builder pattern (filter-only, no vector search). */
|
|
21
|
+
buildQuery(): QueryBuilder
|
|
22
|
+
/** Update metadata for points in the collection. */
|
|
23
|
+
updateMetadata(updates: Array<MetadataUpdate>): Promise<void>
|
|
24
|
+
delete(ids: Array<string>): Promise<void>
|
|
25
|
+
deleteCollection(): Promise<void>
|
|
26
|
+
create(dimension: number, distance: string): Promise<void>
|
|
27
|
+
/**
|
|
28
|
+
* Create the collection with optional dimension.
|
|
29
|
+
*
|
|
30
|
+
* For providers like Chroma that infer dimension from the first insert,
|
|
31
|
+
* you can pass `undefined` for dimension. For other providers, dimension is required.
|
|
32
|
+
*
|
|
33
|
+
* @param dimension - Optional dimension. Use `undefined` for Chroma (infers from first insert).
|
|
34
|
+
* @param distance - Distance metric ("cosine", "euclidean", or "dot").
|
|
35
|
+
*/
|
|
36
|
+
createAuto(dimension?: number | undefined | null, distance?: string | undefined | null): Promise<void>
|
|
37
|
+
insertBatch(points: Array<Point>, batchSize?: number | undefined | null, parallel?: number | undefined | null): Promise<void>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Main client for the Embex vector database. */
|
|
41
|
+
export declare class EmbexClient {
|
|
42
|
+
/**
|
|
43
|
+
* Create a new Embex client.
|
|
44
|
+
*
|
|
45
|
+
* @param provider - The database provider (e.g., 'qdrant', 'pinecone').
|
|
46
|
+
* @param url - The connection URL.
|
|
47
|
+
* @param apiKey - Optional API key.
|
|
48
|
+
*/
|
|
49
|
+
constructor(provider: string, url: string, apiKey?: string | undefined | null)
|
|
50
|
+
/**
|
|
51
|
+
* Create a new Embex client with async initialization.
|
|
52
|
+
* Required for providers like 'milvus', 'pgvector', and 'lancedb'.
|
|
53
|
+
*
|
|
54
|
+
* @param provider - The database provider.
|
|
55
|
+
* @param url - The connection URL.
|
|
56
|
+
* @param apiKey - Optional API key.
|
|
57
|
+
*/
|
|
58
|
+
static newAsync(provider: string, url: string, apiKey?: string | undefined | null): Promise<EmbexClient>
|
|
59
|
+
collection(name: string): Collection
|
|
60
|
+
/**
|
|
61
|
+
* Run database migrations.
|
|
62
|
+
*
|
|
63
|
+
* @param migrations - Array of migration objects
|
|
64
|
+
* {
|
|
65
|
+
* version: string,
|
|
66
|
+
* operations: [{ type: 'create_collection', schema: ... }, { type: 'delete_collection', name: ... }],
|
|
67
|
+
* down_operations: [...]
|
|
68
|
+
* }
|
|
69
|
+
*/
|
|
70
|
+
runMigrations(migrations: Array<MigrationInput>): Promise<void>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export declare class QueryBuilder {
|
|
74
|
+
limit(limit: number): QueryBuilder
|
|
75
|
+
offset(offset: number): QueryBuilder
|
|
76
|
+
includeVector(include: boolean): QueryBuilder
|
|
77
|
+
includeMetadata(include: boolean): QueryBuilder
|
|
78
|
+
filter(filter: any): QueryBuilder
|
|
79
|
+
aggregation(aggType: string): QueryBuilder
|
|
80
|
+
execute(): Promise<SearchResponse>
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export declare class SearchBuilder {
|
|
84
|
+
limit(limit: number): SearchBuilder
|
|
85
|
+
offset(offset: number): SearchBuilder
|
|
86
|
+
includeVector(include: boolean): SearchBuilder
|
|
87
|
+
includeMetadata(include: boolean): SearchBuilder
|
|
88
|
+
filter(filter: any): SearchBuilder
|
|
89
|
+
aggregation(aggType: string): SearchBuilder
|
|
90
|
+
execute(): Promise<SearchResponse>
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export declare function cli(args: Array<string>): Promise<void>
|
|
94
|
+
|
|
95
|
+
export interface MetadataUpdate {
|
|
96
|
+
/** Point ID to update. */
|
|
97
|
+
id: string
|
|
98
|
+
/** Metadata updates to apply. */
|
|
99
|
+
updates: Record<string, any>
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface MigrationInput {
|
|
103
|
+
version: string
|
|
104
|
+
operations?: any
|
|
105
|
+
downOperations?: any
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A point in the vector database. */
|
|
109
|
+
export interface Point {
|
|
110
|
+
id: string
|
|
111
|
+
vector: Array<number>
|
|
112
|
+
metadata?: Record<string, any>
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface SearchOptions {
|
|
116
|
+
/** Number of results to return. */
|
|
117
|
+
limit?: number
|
|
118
|
+
/** Metadata filter. */
|
|
119
|
+
filter?: any
|
|
120
|
+
/** Whether to include metadata in results. */
|
|
121
|
+
includeMetadata?: boolean
|
|
122
|
+
/** Whether to include vector in results. */
|
|
123
|
+
includeVector?: boolean
|
|
124
|
+
/** Pagination offset. */
|
|
125
|
+
offset?: number
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface SearchResponse {
|
|
129
|
+
results: Array<SearchResult>
|
|
130
|
+
aggregations: Record<string, any>
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface SearchResult {
|
|
134
|
+
id: string
|
|
135
|
+
score: number
|
|
136
|
+
vector?: Array<number>
|
|
137
|
+
metadata?: Record<string, any>
|
|
138
|
+
}
|