Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite #173

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["nrwl.angular-console", "esbenp.prettier-vscode"]
"recommendations": ["esbenp.prettier-vscode"]
}
12 changes: 8 additions & 4 deletions core/embedjs-interfaces/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-interfaces to align it with other projects, there were no code changes.

## 0.1.19 (2024-11-26)

This was a version bump only for this package to align it with other projects, there were no code changes.

## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-interfaces to align it with other projects, there were no code changes.

## 0.1.17 (2024-11-05)

### 🚀 Features
Expand Down
2 changes: 1 addition & 1 deletion core/embedjs-interfaces/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@llm-tools/embedjs-interfaces",
"version": "0.1.18",
"version": "0.1.19",
"description": "Interfaces for extending the embedjs ecosystem",
"dependencies": {
"@langchain/core": "^0.3.18",
Expand Down
12 changes: 8 additions & 4 deletions core/embedjs-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-utils to align it with other projects, there were no code changes.

## 0.1.19 (2024-11-26)

This was a version bump only for this package to align it with other projects, there were no code changes.

## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-utils to align it with other projects, there were no code changes.

## 0.1.17 (2024-11-05)

### 🚀 Features
Expand Down
4 changes: 2 additions & 2 deletions core/embedjs-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@llm-tools/embedjs-utils",
"version": "0.1.18",
"version": "0.1.19",
"description": "Useful util functions when extending the embedjs ecosystem",
"dependencies": {
"@llm-tools/embedjs-interfaces": "0.1.18"
"@llm-tools/embedjs-interfaces": "0.1.19"
},
"type": "module",
"main": "./src/index.js",
Expand Down
12 changes: 8 additions & 4 deletions core/embedjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 0.1.18 (2024-11-13)

This was a version bump only for embedjs to align it with other projects, there were no code changes.

## 0.1.19 (2024-11-26)

This was a version bump only for this package to align it with other projects, there were no code changes.

## 0.1.18 (2024-11-13)

This was a version bump only for embedjs to align it with other projects, there were no code changes.

## 0.1.17 (2024-11-05)

### 🚀 Features
Expand Down
6 changes: 3 additions & 3 deletions core/embedjs/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"type": "module",
"name": "@llm-tools/embedjs",
"version": "0.1.18",
"version": "0.1.19",
"description": "A NodeJS RAG framework to easily work with LLMs and custom datasets",
"dependencies": {
"@langchain/textsplitters": "^0.1.0",
"@llm-tools/embedjs-interfaces": "0.1.18",
"@llm-tools/embedjs-utils": "0.1.18",
"@llm-tools/embedjs-interfaces": "0.1.19",
"@llm-tools/embedjs-utils": "0.1.19",
"debug": "^4.3.7",
"langchain": "^0.3.6",
"md5": "^2.3.0",
Expand Down
12 changes: 8 additions & 4 deletions databases/embedjs-astra/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-astra to align it with other projects, there were no code changes.

## 0.1.19 (2024-11-26)

This was a version bump only for this package to align it with other projects, there were no code changes.

## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-astra to align it with other projects, there were no code changes.

## 0.1.17 (2024-11-05)

### 🚀 Features
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-astra/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@llm-tools/embedjs-astradb",
"version": "0.1.18",
"version": "0.1.19",
"description": "Add AstraDB support to embedjs",
"dependencies": {
"@datastax/astra-db-ts": "^1.5.0",
"@llm-tools/embedjs-interfaces": "0.1.18",
"@llm-tools/embedjs-interfaces": "0.1.19",
"debug": "^4.3.7"
},
"type": "module",
Expand Down
12 changes: 8 additions & 4 deletions databases/embedjs-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-cosmos to align it with other projects, there were no code changes.

## 0.1.19 (2024-11-26)

This was a version bump only for this package to align it with other projects, there were no code changes.

## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-cosmos to align it with other projects, there were no code changes.

## 0.1.17 (2024-11-05)

### 🚀 Features
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-cosmos/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@llm-tools/embedjs-cosmos",
"version": "0.1.18",
"version": "0.1.19",
"description": "Add CosmosDB support to embedjs",
"dependencies": {
"@azure/cosmos": "^4.2.0",
"@llm-tools/embedjs-interfaces": "0.1.18",
"@llm-tools/embedjs-interfaces": "0.1.19",
"debug": "^4.3.7"
},
"type": "module",
Expand Down
12 changes: 8 additions & 4 deletions databases/embedjs-hnswlib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-hnswlib to align it with other projects, there were no code changes.

## 0.1.19 (2024-11-26)

This was a version bump only for this package to align it with other projects, there were no code changes.

## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-hnswlib to align it with other projects, there were no code changes.

## 0.1.17 (2024-11-05)

### 🚀 Features
Expand Down
4 changes: 2 additions & 2 deletions databases/embedjs-hnswlib/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@llm-tools/embedjs-hnswlib",
"version": "0.1.18",
"version": "0.1.19",
"description": "Add HNSWLib support to embedjs",
"dependencies": {
"@llm-tools/embedjs-interfaces": "0.1.18",
"@llm-tools/embedjs-interfaces": "0.1.19",
"debug": "^4.3.7",
"hnswlib-node": "^3.0.0"
},
Expand Down
12 changes: 8 additions & 4 deletions databases/embedjs-lancedb/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-lancedb to align it with other projects, there were no code changes.

## 0.1.19 (2024-11-26)

This was a version bump only for this package to align it with other projects, there were no code changes.

## 0.1.18 (2024-11-13)

This was a version bump only for embedjs-lancedb to align it with other projects, there were no code changes.

## 0.1.17 (2024-11-05)

### 🚀 Features
Expand Down
7 changes: 4 additions & 3 deletions databases/embedjs-lancedb/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "@llm-tools/embedjs-lancedb",
"version": "0.1.18",
"version": "0.1.19",
"description": "Add LanceDb support to embedjs",
"dependencies": {
"@lancedb/lancedb": "^0.13.0",
"@llm-tools/embedjs-interfaces": "0.1.18",
"compute-cosine-similarity": "^1.1.0"
"@llm-tools/embedjs-interfaces": "0.1.19",
"compute-cosine-similarity": "^1.1.0",
"debug": "^4.3.7"
},
"type": "module",
"main": "./src/index.js",
Expand Down
7 changes: 7 additions & 0 deletions databases/embedjs-lancedb/src/lance-db.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as fsOld from 'node:fs';
import * as fs from 'node:fs/promises';
import createDebugMessages from 'debug';
import similarity from 'compute-cosine-similarity';
import { Table, connect } from '@lancedb/lancedb';

import { BaseVectorDatabase, ExtractChunkData, InsertChunkData } from '@llm-tools/embedjs-interfaces';

export class LanceDb implements BaseVectorDatabase {
private readonly debug = createDebugMessages('embedjs:vector:LanceDb');
private static readonly STATIC_DB_NAME = 'vectors';
private readonly isTemp: boolean = true;
private readonly path: string;
Expand All @@ -18,13 +20,16 @@ export class LanceDb implements BaseVectorDatabase {

async init({ dimensions }: { dimensions: number }) {
if (!this.isTemp && !fsOld.existsSync(this.path)) {
this.debug(`Creating dir at path - ${this.path}`);
await fs.mkdir(this.path);
}

const dir = await (this.isTemp ? fs.mkdtemp(this.path) : this.path);
this.debug(`Connecting to path - ${dir}`);
const client = await connect(dir);

const list = await client.tableNames();
this.debug.log(`Table names found - [${list.join(',')}]`);
if (list.indexOf(LanceDb.STATIC_DB_NAME) > -1) this.table = await client.openTable(LanceDb.STATIC_DB_NAME);
else {
//TODO: You can add a proper schema instead of a sample record now but it requires another package apache-arrow; another install on downstream as well
Expand Down Expand Up @@ -56,12 +61,14 @@ export class LanceDb implements BaseVectorDatabase {
};
});

this.debug.log(`Executing insert of ${mapped.length} entries`);
await this.table.add(mapped);
return mapped.length; //TODO: check if vectorDb has addressed the issue where add returns undefined
}

async similaritySearch(query: number[], k: number): Promise<ExtractChunkData[]> {
const results = await this.table.search(query).limit(k).toArray();
this.debug.log(`Query found ${results.length} entries`);

return (
results
Expand Down
5 changes: 5 additions & 0 deletions databases/embedjs-libsql/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 0.1.19 (2024-11-26)

### 🚀 Features

- added sqlite vector database ([cd27bc5](https://github.com/llm-tools/embedJs/commit/cd27bc5))
8 changes: 8 additions & 0 deletions databases/embedjs-libsql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# embedjs-libsql

<p>
<a href="https://www.npmjs.com/package/@llm-tools/embedjs" target="_blank"><img alt="NPM Version" src="https://img.shields.io/npm/v/%40llm-tools/embedjs?style=for-the-badge"></a>
<a href="https://www.npmjs.com/package/@llm-tools/embedjs" target="_blank"><img alt="License" src="https://img.shields.io/npm/l/%40llm-tools%2Fembedjs?style=for-the-badge"></a>
</p>

This package extends and offers additional functionality to [embedJs](https://www.npmjs.com/package/@llm-tools/embedjs). Refer to the documentation there for more details.
20 changes: 20 additions & 0 deletions databases/embedjs-libsql/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import baseConfig from '../../eslint.config.js';
import parser from '@nx/eslint-plugin';

export default [
...baseConfig,
{
files: ['**/*.json'],
rules: {
'@nx/dependency-checks': [
'error',
{
ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'],
},
],
},
languageOptions: {
parser,
},
},
];
39 changes: 39 additions & 0 deletions databases/embedjs-libsql/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@llm-tools/embedjs-libsql",
"version": "0.1.19",
"description": "Add LibSQL support to embedjs",
"dependencies": {
"@libsql/client": "^0.14.0",
"@llm-tools/embedjs-interfaces": "0.1.19",
"debug": "^4.3.7"
},
"type": "module",
"main": "./src/index.js",
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
},
"keywords": [
"llm",
"ai",
"gpt3",
"chain",
"prompt",
"prompt engineering",
"chatgpt",
"machine learning",
"ml",
"anthropic",
"embeddings",
"vectorstores"
],
"author": "K V Adhityan",
"bugs": {
"url": "https://github.com/llm-tools/embedjs/issues"
},
"homepage": "https://github.com/llm-tools/embedjs#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/llm-tools/embedjs.git"
}
}
29 changes: 29 additions & 0 deletions databases/embedjs-libsql/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "embedjs-libsql",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "databases/embedjs-libsql/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/esm/embedjs-libsql",
"main": "databases/embedjs-libsql/src/index.ts",
"tsConfig": "databases/embedjs-libsql/tsconfig.lib.json",
"assets": ["databases/embedjs-libsql/*.md"]
}
},
"build-cjs": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"dependsOn": ["^build-cjs"],
"options": {
"outputPath": "dist/cjs/embedjs-libsql",
"main": "databases/embedjs-libsql/src/index.ts",
"tsConfig": "databases/embedjs-libsql/tsconfig.cjs.json"
}
}
}
}
1 change: 1 addition & 0 deletions databases/embedjs-libsql/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './libsql-db.js';
Loading