ai-database 0.0.0-development

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 AI Primitives
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # ai-database
2
+
3
+ [![npm version](https://badge.fury.io/js/ai-database.svg)](https://badge.fury.io/js/ai-database)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ AI-native database abstraction with hybrid vector search capabilities for synthetic data, tool-calling, and RAG applications.
7
+
8
+ ## Features
9
+ - Hybrid vector search optimized for AI workloads
10
+ - Synthetic data generation and management
11
+ - Tool-calling interface compatible with major AI SDKs
12
+ - Built-in support for RAG (Retrieval Augmented Generation)
13
+ - Seamless integration with mdxdb for document storage
14
+
15
+ ## Installation
16
+ ```bash
17
+ npm install ai-database
18
+ # or
19
+ pnpm add ai-database
20
+ # or
21
+ yarn add ai-database
22
+ ```
23
+
24
+ ## Quick Start
25
+ ```typescript
26
+ import { createDatabase } from 'ai-database'
27
+
28
+ // Initialize database with vector search capabilities
29
+ const db = createDatabase({
30
+ namespace: 'my-app',
31
+ vectorSearch: true
32
+ })
33
+
34
+ // Store documents with embeddings
35
+ await db.collection('documents').store({
36
+ content: 'Example document',
37
+ embeddings: [0.1, 0.2, 0.3]
38
+ })
39
+
40
+ // Perform hybrid search
41
+ const results = await db.collection('documents').search({
42
+ query: 'example',
43
+ vector: [0.1, 0.2, 0.3],
44
+ threshold: 0.8
45
+ })
46
+ ```
47
+
48
+ ## Tool Integration
49
+ ai-database exports AI-compatible tools that work with any LLM supporting function calling:
50
+
51
+ ```typescript
52
+ import { tools } from 'ai-database'
53
+
54
+ // Use with any AI SDK (Vercel AI, LangChain, etc)
55
+ const searchTool = tools.vectorSearch({
56
+ collection: 'documents',
57
+ namespace: 'my-app'
58
+ })
59
+ ```
60
+
61
+ ## Integration with AI Primitives
62
+ ai-database is designed to work seamlessly with other AI Primitives packages:
63
+
64
+ - **ai-functions**: Provides database operations as callable AI functions
65
+ - **ai-workflows**: Enables database integration in AI workflow definitions
66
+ - **ai-agents**: Offers database access tools for AI agents
67
+
68
+ ## API Reference
69
+ [API documentation link]
70
+
71
+ ## Dependencies
72
+ Built on top of [mdxdb](https://github.com/ai-primitives/mdxdb) for robust document storage and vector search capabilities.
@@ -0,0 +1,46 @@
1
+ import { AIDocument } from './document';
2
+ import { AIVectorSearchOptions } from './vector';
3
+ /**
4
+ * Configuration options for the AI-native database
5
+ */
6
+ export interface DatabaseConfig {
7
+ /**
8
+ * Database name or identifier
9
+ */
10
+ name: string;
11
+ /**
12
+ * Optional vector search configuration
13
+ */
14
+ vectorSearch?: {
15
+ /**
16
+ * Dimensions for vector embeddings
17
+ */
18
+ dimensions?: number;
19
+ /**
20
+ * Model to use for embeddings
21
+ */
22
+ model?: string;
23
+ };
24
+ /**
25
+ * Optional synthetic data generation configuration
26
+ */
27
+ synthetic?: {
28
+ /**
29
+ * Model to use for synthetic data generation
30
+ */
31
+ model?: string;
32
+ };
33
+ }
34
+ /**
35
+ * Database provider interface
36
+ */
37
+ export interface DatabaseProvider {
38
+ /**
39
+ * Query documents using AI-powered vector search
40
+ */
41
+ query(options: AIVectorSearchOptions): Promise<AIDocument[]>;
42
+ /**
43
+ * Insert a document into the database
44
+ */
45
+ insert(document: AIDocument): Promise<void>;
46
+ }
@@ -0,0 +1,15 @@
1
+ import type { Document } from './mdxdb/types';
2
+ export interface AIDocument extends Document {
3
+ metadata?: {
4
+ model?: string;
5
+ temperature?: number;
6
+ tokens?: number;
7
+ provider?: string;
8
+ };
9
+ synthetic?: boolean;
10
+ toolCalls?: Array<{
11
+ name: string;
12
+ arguments: Record<string, unknown>;
13
+ result?: unknown;
14
+ }>;
15
+ }
@@ -0,0 +1,5 @@
1
+ export * from './document';
2
+ export * from './vector';
3
+ export * from './tools';
4
+ export * from './synthetic';
5
+ export * from './database';
@@ -0,0 +1,7 @@
1
+ export interface EmbeddingOptions {
2
+ dimensions?: number;
3
+ model?: string;
4
+ }
5
+ export interface EmbeddingProvider {
6
+ embed(text: string, options?: EmbeddingOptions): Promise<number[]>;
7
+ }
@@ -0,0 +1,59 @@
1
+ import type { MDXLD } from 'mdxld';
2
+ export interface Document extends MDXLD {
3
+ embeddings?: number[];
4
+ collections?: string[];
5
+ }
6
+ export interface VectorSearchOptions {
7
+ vector?: number[];
8
+ query?: string;
9
+ filter?: Record<string, unknown>;
10
+ k?: number;
11
+ threshold?: number;
12
+ }
13
+ export interface NamespaceOptions {
14
+ defaultNamespace?: string;
15
+ enforceHttps?: boolean;
16
+ maxPathDepth?: number;
17
+ allowSubdomains?: boolean;
18
+ }
19
+ export interface DatabaseOptions {
20
+ namespace: string;
21
+ baseUrl?: string;
22
+ options?: NamespaceOptions;
23
+ }
24
+ export interface CollectionOptions {
25
+ path: string;
26
+ database: DatabaseProvider;
27
+ }
28
+ export interface DatabaseProvider<T extends Document = Document> {
29
+ namespace: string;
30
+ connect(): Promise<void>;
31
+ disconnect(): Promise<void>;
32
+ list(): Promise<string[]>;
33
+ collection(name: string): CollectionProvider<T>;
34
+ [key: string]: DatabaseProvider<T> | CollectionProvider<T> | string | (() => Promise<void>) | (() => Promise<string[]>) | ((name: string) => CollectionProvider<T>);
35
+ }
36
+ export type FilterQuery<T> = {
37
+ [K in keyof T]?: T[K] | {
38
+ $eq?: T[K];
39
+ $gt?: T[K];
40
+ $gte?: T[K];
41
+ $lt?: T[K];
42
+ $lte?: T[K];
43
+ $in?: T[K][];
44
+ $nin?: T[K][];
45
+ };
46
+ };
47
+ export interface SearchOptions<T extends Document = Document> {
48
+ filter?: FilterQuery<T>;
49
+ threshold?: number;
50
+ limit?: number;
51
+ offset?: number;
52
+ includeVectors?: boolean;
53
+ }
54
+ export interface CollectionProvider<T extends Document = Document> {
55
+ path: string;
56
+ find(filter: FilterQuery<T>, options?: SearchOptions<T>): Promise<T[]>;
57
+ search(query: string, options?: SearchOptions<T>): Promise<T[]>;
58
+ vectorSearch(options: VectorSearchOptions & SearchOptions<T>): Promise<T[]>;
59
+ }
@@ -0,0 +1,9 @@
1
+ export interface SyntheticDataOptions {
2
+ schema: Record<string, unknown>;
3
+ count: number;
4
+ model?: string;
5
+ temperature?: number;
6
+ }
7
+ export interface SyntheticDataProvider {
8
+ generate(options: SyntheticDataOptions): Promise<unknown[]>;
9
+ }
@@ -0,0 +1,10 @@
1
+ export interface ToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ parameters: Record<string, unknown>;
5
+ returns: Record<string, unknown>;
6
+ }
7
+ export interface ToolProvider {
8
+ namespace: string;
9
+ tools: ToolDefinition[];
10
+ }
@@ -0,0 +1,16 @@
1
+ import type { VectorSearchOptions } from './mdxdb/types';
2
+ import type { EmbeddingOptions, EmbeddingProvider } from './mdxdb/embedding';
3
+ export interface AIVectorSearchOptions extends VectorSearchOptions {
4
+ rerank?: boolean;
5
+ hybridWeight?: number;
6
+ contextWindow?: number;
7
+ }
8
+ export interface AIEmbeddingOptions extends EmbeddingOptions {
9
+ provider?: string;
10
+ batchSize?: number;
11
+ normalize?: boolean;
12
+ }
13
+ export interface AIEmbeddingProvider extends EmbeddingProvider {
14
+ batchEmbed?(texts: string[], options?: AIEmbeddingOptions): Promise<number[][]>;
15
+ normalize?(vector: number[]): number[];
16
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "ai-database",
3
+ "version": "0.0.0-development",
4
+ "description": "AI-native database abstraction with hybrid vector search for synthetic data and RAG applications. Currently using local mdxdb types until @mdxdb/types is published.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "files": [
9
+ "dist/types"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "test": "vitest",
14
+ "lint": "eslint .",
15
+ "format": "prettier --write ."
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^20.0.0",
19
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
20
+ "@typescript-eslint/parser": "^6.0.0",
21
+ "eslint": "^8.0.0",
22
+ "eslint-config-prettier": "^9.0.0",
23
+ "mdxld": "^0.1.0",
24
+ "prettier": "^3.0.0",
25
+ "typescript": "^5.0.0",
26
+ "vitest": "^1.0.0"
27
+ },
28
+ "dependencies": {
29
+ "@ai-sdk/openai": "^1.0.8",
30
+ "ai": "^2.2.37",
31
+ "openai": "^4.76.3"
32
+ }
33
+ }