@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.
Files changed (55) hide show
  1. package/README.md +70 -97
  2. package/bin/embex.js +0 -0
  3. package/bun.lockb +0 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +17 -0
  7. package/dist/native.d.ts +138 -0
  8. package/dist/native.js +579 -0
  9. package/dist/src/index.d.ts +8 -0
  10. package/dist/src/index.d.ts.map +1 -0
  11. package/dist/src/index.js +26 -0
  12. package/dist/src/tests/integration/adapters.test.d.ts +13 -0
  13. package/dist/src/tests/integration/adapters.test.d.ts.map +1 -0
  14. package/dist/src/tests/integration/adapters.test.js +372 -0
  15. package/dist/src/tests/integration/aggregations.test.d.ts +6 -0
  16. package/dist/src/tests/integration/aggregations.test.d.ts.map +1 -0
  17. package/dist/src/tests/integration/aggregations.test.js +96 -0
  18. package/dist/src/tests/integration/api_parity.test.d.ts +6 -0
  19. package/dist/src/tests/integration/api_parity.test.d.ts.map +1 -0
  20. package/dist/src/tests/integration/api_parity.test.js +99 -0
  21. package/dist/src/tests/integration/batch.test.d.ts +2 -0
  22. package/dist/src/tests/integration/batch.test.d.ts.map +1 -0
  23. package/dist/src/tests/integration/batch.test.js +53 -0
  24. package/dist/src/tests/integration/errors.test.d.ts +6 -0
  25. package/dist/src/tests/integration/errors.test.d.ts.map +1 -0
  26. package/dist/src/tests/integration/errors.test.js +133 -0
  27. package/dist/src/tests/integration/features.test.d.ts +2 -0
  28. package/dist/src/tests/integration/features.test.d.ts.map +1 -0
  29. package/dist/src/tests/integration/features.test.js +37 -0
  30. package/dist/src/tests/integration/filters.test.d.ts +6 -0
  31. package/dist/src/tests/integration/filters.test.d.ts.map +1 -0
  32. package/dist/src/tests/integration/filters.test.js +296 -0
  33. package/dist/src/tests/integration/metadata.test.d.ts +6 -0
  34. package/dist/src/tests/integration/metadata.test.d.ts.map +1 -0
  35. package/dist/src/tests/integration/metadata.test.js +167 -0
  36. package/dist/src/tests/integration/migrations.test.d.ts +2 -0
  37. package/dist/src/tests/integration/migrations.test.d.ts.map +1 -0
  38. package/dist/src/tests/integration/migrations.test.js +55 -0
  39. package/dist/src/tests/integration/pooling.test.d.ts +6 -0
  40. package/dist/src/tests/integration/pooling.test.d.ts.map +1 -0
  41. package/dist/src/tests/integration/pooling.test.js +56 -0
  42. package/dist/src/tests/integration/search.test.d.ts +2 -0
  43. package/dist/src/tests/integration/search.test.d.ts.map +1 -0
  44. package/dist/src/tests/integration/search.test.js +37 -0
  45. package/dist/src/tests/integration/streaming.test.d.ts +2 -0
  46. package/dist/src/tests/integration/streaming.test.d.ts.map +1 -0
  47. package/dist/src/tests/integration/streaming.test.js +42 -0
  48. package/dist/src/tests/unit/basic.test.d.ts +2 -0
  49. package/dist/src/tests/unit/basic.test.d.ts.map +1 -0
  50. package/dist/src/tests/unit/basic.test.js +23 -0
  51. package/dist/src/tests/unit/errors.test.d.ts +2 -0
  52. package/dist/src/tests/unit/errors.test.d.ts.map +1 -0
  53. package/dist/src/tests/unit/errors.test.js +19 -0
  54. package/package.json +7 -6
  55. package/tsconfig.json +2 -0
package/README.md CHANGED
@@ -1,139 +1,112 @@
1
1
  # Embex (Node.js)
2
2
 
3
- **The Universal Vector Database ORM.** One API for Qdrant, Pinecone, Chroma, LanceDB, and more.
3
+ **The fastest way to add vector search to your app.**
4
4
 
5
- Embex is a high-performance, universal client for vector databases, built on a shared Rust core related to [BridgeRust](https://github.com/bridgerust/bridgerust).
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
- - **Unified API**: Switch providers instantly. "Write once, run anywhere."
10
- - **Performance**: Powered by Rust with SIMD acceleration.
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
- **Try Embex in 30 seconds - No setup required!** Uses LanceDB embedded mode (no server needed).
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
- // LanceDB embedded - zero setup, just a local path
36
- const client = await EmbexClient.newAsync("lancedb", "./data");
37
- const collection = client.collection("documents");
38
-
39
- // Create collection
40
- await collection.create(768, "cosine");
41
-
42
- // Insert data
43
- await collection.insert([
44
- {
45
- id: "1",
46
- vector: Array(768).fill(0.1),
47
- metadata: { text: "Hello World" },
48
- },
49
- ]);
50
-
51
- // Search
52
- const results = await collection.search(Array(768).fill(0.1), 5);
53
- console.log(results.results);
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
- **Run it:** `npx tsx examples/lancedb/node/quickstart.ts`
60
-
61
- ### All Provider Quick Starts
80
+ ## 🗺️ Development Production Roadmap
62
81
 
63
- Try Embex with any provider! Same API, different backend:
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
- | Provider | Setup | Quick Start |
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
- > 💡 **Same API everywhere!** Just change the provider name - all code stays the same. See [examples/README.md](../../../../examples/README.md) for setup instructions.
91
+ Ready for production? Just change the initialization line.
73
92
 
74
- ### 5. Filtered Search (Builder Pattern)
93
+ **From LanceDB (Dev):**
75
94
 
76
95
  ```typescript
77
- const results = await collection.buildSearch([0.1, 0.2, ...])
78
- .limit(10)
79
- .filter({
80
- course: "CS101"
81
- })
82
- .execute();
96
+ const client = await EmbexClient.newAsync("lancedb://./data");
83
97
  ```
84
98
 
85
- ## ☁️ Connecting to Cloud Providers
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://xyz-example.eu-central.aws.cloud.qdrant.io:6333",
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
- - **Main Repository**: [github.com/bridgerust/bridgerust](https://github.com/bridgerust/bridgerust)
138
- - **Issues**: [github.com/bridgerust/bridgerust/issues](https://github.com/bridgerust/bridgerust/issues)
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
@@ -0,0 +1,2 @@
1
+ export * from "./src";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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);
@@ -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
+ }