npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dbsense-ai

v1.1.3

Published

<div align="center"> <a href="https://refine.dev/"> <img alt="dbsense ai logo" src="https://github.com/vedanti-u/readme-assets/blob/main/dbsense-ai-logo.jpeg"> </a> </div> <!-- <div style="font-family: 'Lucida Console', 'Courier New', monospace;

Downloads

25

Readme

Awesome OpenSSF Best Practices npm version Contributor Covenant

What is DbSenseAi

DbSenseAI is a fast and lightweight library that simplifies chatting with your database. Unlike traditional methods, it doesn't need to embed all your database data. Instead, it focuses only on the schema, making it efficient and quick.

Features:

  • Efficient Schema Embedding: Only embeds schema, skipping the need to embed all database data.

  • Fast Database Interaction: Enables quick communication with your database.

  • Resource Optimization: Saves resources by avoiding unnecessary data embedding.

  • Versatile Integration: Works well with various database systems.

How DbSenseAi works ?

  sequenceDiagram
    participant User
    participant App
    participant LLM_Model
    participant Database
    
    User->>App: Provides data (Schema of tables)
    App->>LLM_Model: Sends schema
    LLM_Model->>App: Creates Vector Embedding
    App->>App: Stores Vector Embedding in Local File
    App->>User: Acknowledgement
    
    User->>App: Asks query: "All students passed with above 80 marks"
    App->>LLM_Model: Sends query with Vector Embedding
    LLM_Model->>LLM_Model: Converts to SQL
    LLM_Model->>App: Sends SQL
    App->>Database: Sends SQL
    Database->>Database: Processes SQL
    Database-->>App: Returns response
    App-->>User: Sends response

The sequence diagram illustrates the process flow of a system where a user provides data to DBSenseAi, which includes schema information of tables. DBSenseAi forwards this schema to the Language Model (LLM_Model), which generates Vector Embeddings. These embeddings are stored locally by DBSenseAi. When the user queries for students who passed with above 80 marks, DBSenseAi sends this query along with the embeddings to the LLM_Model, which converts it into SQL. The SQL is then forwarded to the Database, processed, and the response is sent back to DBSenseAi, which in turn delivers it to the user.

Class Diagram


classDiagram
    class User {
        +ProvidesData()
        +AsksQuery()
    }
    class LLMService {
        -vectorStore: HNSWLib | undefined
        -model: OpenAI
        -vectorStorePath: string
        -openAIEmbeddings: OpenAIEmbeddings
        +createTable(sqlQueryForTable: string): void
        +updateTable(sqlQueryForTable: string): void
        -extractTableNameFromCreateQuery(sqlQueryForTable: string): string | null
        -extractTableNameFromUpdateQuery(sqlQueryForTable: string): string | null
        +createVectorEmbeddings(tableString: string): void
        -checkFileExists(filePath: string): Promise<boolean>
        -deleteFile(filePath: string): Promise<void>
    }
    class PromptService {
        -vectorStore: HNSWLib | undefined
        -model: OpenAI
        -vectorStorePath: string
        -openAIEmbeddings: OpenAIEmbeddings
        -rawData: string
        -jsonData: any
        +createSqlQuery(question: string): void
        +checkFileExists(filePath: string): Promise<boolean>
        +summarizeResponse(question: string, answer: any): void
        +parseMessage(unformatedPrompt: string, ...args: string[]): string | undefined
    }
    class DBService {
        -connection: dbconfig
        -client: Client
        +queryDatabase(inputQuery: string): Promise<QueryResult>
        +connect(): Promise<void>
    }
    class DbSenseAi {
        -dbService: DBService
        -promptService: PromptService
        -llmService: LLMService
        +createTable(createQuery: string): Promise<boolean>
        +updateTable(updateQuery: string): Promise<boolean>
        +ask(question: string): Promise<QuestionResponse>
    }

    class OpenAIEmbeddings {
        // properties and methods
    }
    class OpenAI {
        // properties and methods
    }
    class HNSWLib {
        // properties and methods
    }
    class dbconfig {
        // properties
    }
    class Client {
        // properties and methods
    }
    class QueryResult {
        // properties and methods
    }
    class QuestionResponse {
        // properties and methods
    }

    User --> DbSenseAi : Uses
    DbSenseAi --> LLMService : Uses
    DbSenseAi --> PromptService : Uses
    DbSenseAi --> DBService : Uses
    PromptService --> OpenAIEmbeddings : Uses
    PromptService --> OpenAI : Uses
    LLMService --> OpenAIEmbeddings : Uses
    LLMService --> OpenAI : Uses
    LLMService --> HNSWLib : Uses
    DBService --> dbconfig : Contains
    DBService --> Client : Contains
    DBService --> QueryResult : Returns
    DbSenseAi --> QuestionResponse : Returns



⚡ Try DbSenseAi

Prerequisites

  • make

    $ sudo apt install make

    Check version

    $ make -version
  • G++

    $ sudo apt install g++

    Check version

    $ g++ --version

Installation

$ npm i dbsense-ai

Setting-up .env

Your .env file should include

export OPENAI_API_KEY=<YOUR_OPENAI_KEY>
DB_DATABASE=<YOUR_DATABASE_NAME>
DB_HOST=<YOUR_DATABASE_HOST>
DB_PORT=<YOUR_DATABASE_PORT>
DB_USER=<YOUR_DATABASE_USER>
DB_PASSWORD=<YOUR_DATABASE_PASSWORD>

Once the package is installed, you can import the library using import or require approach:

var DbSenseAi = require("dbsense-ai");

Instanciate the DbSenseAi class

const dbsenseai = new DbSenseAi();

Usage

Add your create table query inside the createTable() function

await dbsenseai.createTable(
  "CREATE TABLE cosmetics (brand VARCHAR(100) NOT NULL,product_type VARCHAR(100) NOT NULL,product_price NUMERIC(10, 2));"
);

Add your prompt inside the ask() function

let response = await dbsenseai.ask(
  "Give me name of all brands sorted in ascending order of price"
);

You can get the response as table and summary

console.table(response.table);
console.log(response.summary);

Contributing to Library

Prerequisites

If you don't have git on your machine, install it.

  • make

    $ sudo apt install make

    Check version

    $ make -version
  • G++

    $ sudo apt install g++

    Check version

    $ g++ --version

Fork this repository

Fork this repository by clicking on the fork button on the top of this page. This will create a copy of this repository in your account.

Clone the repository

Open a terminal and run the following git command:

git clone "COPIED_URL"

e.g : git clone https://github.com/vedanti-u/db.ai.git


Install dependencies

npm install

Create a branch

Change to the repository directory on your computer (if you are not already there):

$ cd dbsense-ai

Now create a branch using the git checkout command:

$ git checkout -b new-branch-name

e.g : git checkout -b llm-prompt-support

Name your branch according to the feature you are working on :

e.g : you want to work on creating more llm prompt support, name your branch like llm-prompt-support

(follow this naming convention i.e using "-" in between)

Make necessary changes

Create a .env File with format

export OPENAI_API_KEY=<YOUR_OPENAI_KEY>
DB_DATABASE=<YOUR_DATABASE_NAME>
DB_HOST=<YOUR_DATABASE_HOST>
DB_PORT=<YOUR_DATABASE_PORT>
DB_USER=<YOUR_DATABASE_USER>
DB_PASSWORD=<YOUR_DATABASE_PASSWORD>

Linking the library locally

rm -rf dist
tsc
npm link
npm link dbsense-ai

Testing the library locally

node test/localLibrary.test.ts --env=.env

Create a pull request

$ git add filename.md

where filename is the file you have modified or created

If you are looking to add all the files you have modified in a particular directory, you can stage them all with the following command: git add .

Or, alternatively, you can type git add -all for all new files to be staged.

e.g : $ git push --set-upstream origin optimise-binding

your branch will be merged on code review