@neural-tools/vector-db 0.1.3

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/LICENSE.md ADDED
@@ -0,0 +1,80 @@
1
+ # Neural Tools License
2
+
3
+ Copyright (c) 2025 Luke Amy. All rights reserved.
4
+
5
+ ## License Agreement
6
+
7
+ This software is provided under a dual-license model:
8
+
9
+ ### 1. Free Tier License (MIT)
10
+
11
+ The following components are licensed under the MIT License:
12
+
13
+ - Basic MCP generation functionality
14
+ - Claude command generation
15
+ - Core utilities and types
16
+ - Basic templates
17
+ - Documentation and examples
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining a copy of the free tier components to use, copy, modify, merge, publish, and distribute, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
22
+
23
+ ### 2. Pro/Enterprise License (Proprietary)
24
+
25
+ The following features require a valid Pro or Enterprise license:
26
+
27
+ **Pro Features:**
28
+ - Vector database integration
29
+ - Semantic caching
30
+ - Fine-tuning workflows
31
+ - Cloud deployment templates (AWS/GCP)
32
+ - Premium templates and examples
33
+ - GitHub automation features
34
+
35
+ **Enterprise Features:**
36
+ - White-label support
37
+ - Custom integrations
38
+ - Priority support
39
+ - SLA guarantees
40
+ - Team collaboration features
41
+
42
+ These features are proprietary and may not be used without a valid license key purchased from neural-tools.dev.
43
+
44
+ ### License Terms
45
+
46
+ 1. **Free Tier**: You may use the free tier features for any purpose, including commercial use, under the MIT License terms.
47
+
48
+ 2. **Pro/Enterprise**: You must purchase a license to access Pro or Enterprise features. Each license is:
49
+ - Per-user for individual licenses
50
+ - Per-organization for team/enterprise licenses
51
+ - Non-transferable without written consent
52
+ - Subject to the terms at neural-tools.dev/terms
53
+
54
+ 3. **Source Code**: This repository is private. You may not:
55
+ - Redistribute the source code
56
+ - Create derivative works for redistribution
57
+ - Reverse engineer Pro/Enterprise features
58
+ - Remove or circumvent license checks
59
+
60
+ 4. **Support**: Support is provided based on your license tier:
61
+ - Free: Community support only
62
+ - Pro: Email support (48-hour response)
63
+ - Enterprise: Priority support with SLA
64
+
65
+ ### Warranty Disclaimer
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
68
+
69
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
70
+
71
+ ### Contact
72
+
73
+ For licensing inquiries:
74
+ - Email: licensing@neural-tools.dev
75
+ - Website: https://neural-tools.dev/pricing
76
+ - Support: support@neural-tools.dev
77
+
78
+ ---
79
+
80
+ **Last Updated:** January 2025
@@ -0,0 +1,19 @@
1
+ import { VectorDBConfig, VectorStore } from './types';
2
+ export * from './types';
3
+ export { LocalVectorStore } from './local-store';
4
+ /**
5
+ * Create a vector store instance based on the configuration
6
+ */
7
+ export declare function createVectorStore(config: VectorDBConfig): Promise<VectorStore>;
8
+ /**
9
+ * Helper function to create embeddings from text
10
+ * In production, this would call OpenAI, Anthropic, or other embedding APIs
11
+ */
12
+ export declare function createEmbedding(text: string): Promise<number[]>;
13
+ /**
14
+ * Batch text into chunks for embedding
15
+ */
16
+ export declare function chunkText(text: string, options?: {
17
+ chunkSize?: number;
18
+ overlap?: number;
19
+ }): string[];
package/dist/index.js ADDED
@@ -0,0 +1,87 @@
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
+ exports.LocalVectorStore = void 0;
18
+ exports.createVectorStore = createVectorStore;
19
+ exports.createEmbedding = createEmbedding;
20
+ exports.chunkText = chunkText;
21
+ const local_store_1 = require("./local-store");
22
+ const core_1 = require("@neural-tools/core");
23
+ __exportStar(require("./types"), exports);
24
+ var local_store_2 = require("./local-store");
25
+ Object.defineProperty(exports, "LocalVectorStore", { enumerable: true, get: function () { return local_store_2.LocalVectorStore; } });
26
+ /**
27
+ * Create a vector store instance based on the configuration
28
+ */
29
+ async function createVectorStore(config) {
30
+ switch (config.provider) {
31
+ case 'local':
32
+ return new local_store_1.LocalVectorStore(config);
33
+ case 'pinecone':
34
+ await (0, core_1.requireFeature)('vector-db', 'Vector Database Integration');
35
+ throw new Error('Pinecone integration coming soon. Use local provider for now.');
36
+ case 'qdrant':
37
+ await (0, core_1.requireFeature)('vector-db', 'Vector Database Integration');
38
+ throw new Error('Qdrant integration coming soon. Use local provider for now.');
39
+ case 'chromadb':
40
+ await (0, core_1.requireFeature)('vector-db', 'Vector Database Integration');
41
+ throw new Error('ChromaDB integration coming soon. Use local provider for now.');
42
+ default:
43
+ throw new Error(`Unknown vector store provider: ${config.provider}`);
44
+ }
45
+ }
46
+ /**
47
+ * Helper function to create embeddings from text
48
+ * In production, this would call OpenAI, Anthropic, or other embedding APIs
49
+ */
50
+ async function createEmbedding(text) {
51
+ // Placeholder: Simple hash-based embedding for testing
52
+ // In production, use proper embedding models
53
+ const hash = simpleHash(text);
54
+ const dimension = 384; // Common embedding dimension
55
+ const embedding = new Array(dimension).fill(0);
56
+ // Create a deterministic but distributed embedding from hash
57
+ for (let i = 0; i < dimension; i++) {
58
+ embedding[i] = Math.sin(hash + i) * Math.cos(hash / (i + 1));
59
+ }
60
+ // Normalize
61
+ const norm = Math.sqrt(embedding.reduce((sum, val) => sum + val * val, 0));
62
+ return embedding.map(val => val / norm);
63
+ }
64
+ function simpleHash(str) {
65
+ let hash = 0;
66
+ for (let i = 0; i < str.length; i++) {
67
+ const char = str.charCodeAt(i);
68
+ hash = ((hash << 5) - hash) + char;
69
+ hash = hash & hash; // Convert to 32-bit integer
70
+ }
71
+ return Math.abs(hash);
72
+ }
73
+ /**
74
+ * Batch text into chunks for embedding
75
+ */
76
+ function chunkText(text, options = {}) {
77
+ const chunkSize = options.chunkSize || 500;
78
+ const overlap = options.overlap || 50;
79
+ const chunks = [];
80
+ let start = 0;
81
+ while (start < text.length) {
82
+ const end = Math.min(start + chunkSize, text.length);
83
+ chunks.push(text.slice(start, end));
84
+ start += chunkSize - overlap;
85
+ }
86
+ return chunks;
87
+ }
@@ -0,0 +1,30 @@
1
+ import { VectorStore, Vector, QueryResult, QueryOptions, UpsertOptions } from './types';
2
+ /**
3
+ * Simple in-memory vector store for local development and testing
4
+ */
5
+ export declare class LocalVectorStore extends VectorStore {
6
+ private vectors;
7
+ connect(): Promise<void>;
8
+ upsert(vectors: Vector[], options?: UpsertOptions): Promise<void>;
9
+ query(vector: number[], options?: QueryOptions): Promise<QueryResult[]>;
10
+ delete(ids: string[]): Promise<void>;
11
+ fetch(ids: string[]): Promise<Vector[]>;
12
+ deleteNamespace(): Promise<void>;
13
+ disconnect(): Promise<void>;
14
+ /**
15
+ * Calculate cosine similarity between two vectors
16
+ */
17
+ private cosineSimilarity;
18
+ /**
19
+ * Check if metadata matches filter
20
+ */
21
+ private matchesFilter;
22
+ /**
23
+ * Get all vectors (for testing/debugging)
24
+ */
25
+ getAll(): Vector[];
26
+ /**
27
+ * Get count of vectors
28
+ */
29
+ count(): number;
30
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalVectorStore = void 0;
4
+ const types_1 = require("./types");
5
+ /**
6
+ * Simple in-memory vector store for local development and testing
7
+ */
8
+ class LocalVectorStore extends types_1.VectorStore {
9
+ vectors = new Map();
10
+ async connect() {
11
+ // No connection needed for local store
12
+ }
13
+ async upsert(vectors, options) {
14
+ for (const vector of vectors) {
15
+ this.vectors.set(vector.id, vector);
16
+ }
17
+ }
18
+ async query(vector, options) {
19
+ const topK = options?.topK || 10;
20
+ const results = [];
21
+ // Calculate similarity for all vectors
22
+ for (const [id, storedVector] of this.vectors) {
23
+ // Skip if filter doesn't match
24
+ if (options?.filter && !this.matchesFilter(storedVector.metadata, options.filter)) {
25
+ continue;
26
+ }
27
+ const score = this.cosineSimilarity(vector, storedVector.values);
28
+ results.push({
29
+ id,
30
+ score,
31
+ metadata: options?.includeMetadata !== false ? storedVector.metadata : undefined,
32
+ values: options?.includeValues ? storedVector.values : undefined
33
+ });
34
+ }
35
+ // Sort by score descending and take topK
36
+ results.sort((a, b) => b.score - a.score);
37
+ return results.slice(0, topK);
38
+ }
39
+ async delete(ids) {
40
+ for (const id of ids) {
41
+ this.vectors.delete(id);
42
+ }
43
+ }
44
+ async fetch(ids) {
45
+ const results = [];
46
+ for (const id of ids) {
47
+ const vector = this.vectors.get(id);
48
+ if (vector) {
49
+ results.push(vector);
50
+ }
51
+ }
52
+ return results;
53
+ }
54
+ async deleteNamespace() {
55
+ this.vectors.clear();
56
+ }
57
+ async disconnect() {
58
+ // No cleanup needed for local store
59
+ }
60
+ /**
61
+ * Calculate cosine similarity between two vectors
62
+ */
63
+ cosineSimilarity(a, b) {
64
+ if (a.length !== b.length) {
65
+ throw new Error('Vectors must have same length');
66
+ }
67
+ let dotProduct = 0;
68
+ let normA = 0;
69
+ let normB = 0;
70
+ for (let i = 0; i < a.length; i++) {
71
+ dotProduct += a[i] * b[i];
72
+ normA += a[i] * a[i];
73
+ normB += b[i] * b[i];
74
+ }
75
+ return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
76
+ }
77
+ /**
78
+ * Check if metadata matches filter
79
+ */
80
+ matchesFilter(metadata, filter) {
81
+ if (!metadata)
82
+ return false;
83
+ for (const [key, value] of Object.entries(filter)) {
84
+ if (metadata[key] !== value) {
85
+ return false;
86
+ }
87
+ }
88
+ return true;
89
+ }
90
+ /**
91
+ * Get all vectors (for testing/debugging)
92
+ */
93
+ getAll() {
94
+ return Array.from(this.vectors.values());
95
+ }
96
+ /**
97
+ * Get count of vectors
98
+ */
99
+ count() {
100
+ return this.vectors.size;
101
+ }
102
+ }
103
+ exports.LocalVectorStore = LocalVectorStore;
@@ -0,0 +1,61 @@
1
+ export interface VectorDBConfig {
2
+ provider: 'pinecone' | 'qdrant' | 'chromadb' | 'local';
3
+ apiKey?: string;
4
+ endpoint?: string;
5
+ dimension?: number;
6
+ metric?: 'cosine' | 'euclidean' | 'dotproduct';
7
+ namespace?: string;
8
+ }
9
+ export interface Vector {
10
+ id: string;
11
+ values: number[];
12
+ metadata?: Record<string, any>;
13
+ }
14
+ export interface QueryResult {
15
+ id: string;
16
+ score: number;
17
+ metadata?: Record<string, any>;
18
+ values?: number[];
19
+ }
20
+ export interface QueryOptions {
21
+ topK?: number;
22
+ filter?: Record<string, any>;
23
+ includeValues?: boolean;
24
+ includeMetadata?: boolean;
25
+ }
26
+ export interface UpsertOptions {
27
+ namespace?: string;
28
+ batch?: boolean;
29
+ }
30
+ export declare abstract class VectorStore {
31
+ protected config: VectorDBConfig;
32
+ constructor(config: VectorDBConfig);
33
+ /**
34
+ * Initialize the vector store connection
35
+ */
36
+ abstract connect(): Promise<void>;
37
+ /**
38
+ * Insert or update vectors
39
+ */
40
+ abstract upsert(vectors: Vector[], options?: UpsertOptions): Promise<void>;
41
+ /**
42
+ * Query for similar vectors
43
+ */
44
+ abstract query(vector: number[], options?: QueryOptions): Promise<QueryResult[]>;
45
+ /**
46
+ * Delete vectors by ID
47
+ */
48
+ abstract delete(ids: string[], namespace?: string): Promise<void>;
49
+ /**
50
+ * Get vector by ID
51
+ */
52
+ abstract fetch(ids: string[], namespace?: string): Promise<Vector[]>;
53
+ /**
54
+ * Delete all vectors in a namespace
55
+ */
56
+ abstract deleteNamespace(namespace: string): Promise<void>;
57
+ /**
58
+ * Close the connection
59
+ */
60
+ abstract disconnect(): Promise<void>;
61
+ }
package/dist/types.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VectorStore = void 0;
4
+ class VectorStore {
5
+ config;
6
+ constructor(config) {
7
+ this.config = config;
8
+ }
9
+ }
10
+ exports.VectorStore = VectorStore;
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@neural-tools/vector-db",
3
+ "version": "0.1.3",
4
+ "description": "Vector database abstraction layer for Neural Tools",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "license": "SEE LICENSE IN ../../LICENSE.md",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/MacLeanLuke/ai-toolkit.git",
14
+ "directory": "packages/vector-db"
15
+ },
16
+ "dependencies": {
17
+ "@neural-tools/core": "0.1.3"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^20.11.5",
21
+ "typescript": "^5.3.3"
22
+ },
23
+ "peerDependencies": {
24
+ "@pinecone-database/pinecone": "^2.0.0",
25
+ "chromadb": "^1.7.0",
26
+ "@qdrant/js-client-rest": "^1.0.0"
27
+ },
28
+ "peerDependenciesMeta": {
29
+ "@pinecone-database/pinecone": {
30
+ "optional": true
31
+ },
32
+ "chromadb": {
33
+ "optional": true
34
+ },
35
+ "@qdrant/js-client-rest": {
36
+ "optional": true
37
+ }
38
+ },
39
+ "files": [
40
+ "dist"
41
+ ],
42
+ "scripts": {
43
+ "build": "tsc",
44
+ "dev": "tsc --watch",
45
+ "clean": "rm -rf dist",
46
+ "test": "echo 'Tests coming soon'"
47
+ }
48
+ }