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

Implement rag prototpye #22

Merged
merged 32 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ecb31f1
Implement rag prototpye
kevin-on Oct 16, 2024
2483cf1
Merge branch 'main' into kevin/rag
kevin-on Oct 18, 2024
32b93b1
Add settings for RAG
kevin-on Oct 20, 2024
4de4721
Add MarkdownReferenceBlock
kevin-on Oct 20, 2024
7c3d772
Add MentionableFolder and MentionableVault
kevin-on Oct 20, 2024
2a437ad
Implement RAG
kevin-on Oct 20, 2024
797a65b
Update comment
kevin-on Oct 20, 2024
67f2139
Show query progress after submit
kevin-on Oct 20, 2024
61cf2b0
Add comment
kevin-on Oct 20, 2024
e3e83a3
Style QueryProgress
realsnoopso Oct 21, 2024
1e9ba17
Style block header
realsnoopso Oct 21, 2024
61a1dd3
Add icons on Mentionable
realsnoopso Oct 21, 2024
b1e3064
Add icon to Mentionables
realsnoopso Oct 21, 2024
58b193c
Fix lint errors
realsnoopso Oct 21, 2024
10ee558
Add Rag Vault Button
realsnoopso Oct 21, 2024
74b995a
Add Drizzle ORM
kevin-on Oct 21, 2024
27b923e
Merge branch 'kevin/rag' of https://github.com/glowingjade/obsidian-s…
kevin-on Oct 21, 2024
2dc3bfe
Setup migration
kevin-on Oct 21, 2024
1b6a2c5
Handle Vault Search button
kevin-on Oct 21, 2024
a4639d6
Add notice when indexing vault through command
kevin-on Oct 22, 2024
3fa0ec3
Update embedding types
kevin-on Oct 22, 2024
6da3310
Fix lint
kevin-on Oct 22, 2024
b4a8e48
Update dependencies
kevin-on Oct 22, 2024
696bb8d
Resolve review
kevin-on Oct 23, 2024
02743ea
Rename function and variables
kevin-on Oct 23, 2024
9239fdb
Resolve review
kevin-on Oct 23, 2024
6955479
Resolve review
kevin-on Oct 23, 2024
f2ef25d
Fix bug when initializing ragEngine
kevin-on Oct 23, 2024
c0bec53
Fix bug in rag engine intialization
kevin-on Oct 23, 2024
4e74929
Insert vectors batch-wise
kevin-on Oct 23, 2024
f434b60
Set private functions
kevin-on Oct 23, 2024
1f03d90
fix tests by mocking obsidian
glowingjade Oct 23, 2024
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: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ version-bump.mjs
versions.json
package.json
manifest.json
compile-migration.js
import-meta-url-shim.js

# Obsidian
.obsidian
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ main.js
data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store
.DS_Store
12 changes: 12 additions & 0 deletions compile-migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { readMigrationFiles } = require('drizzle-orm/migrator')
const fs = require('node:fs/promises')

async function compileMigrations() {
const migrations = readMigrationFiles({ migrationsFolder: './drizzle/' })

await fs.writeFile('./src/db/migrations.json', JSON.stringify(migrations))

console.log('Migrations compiled!')
}

compileMigrations().catch(console.error)
6 changes: 6 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'drizzle-kit'

export default defineConfig({
dialect: 'postgresql',
schema: './src/db/schema.ts',
})
2 changes: 2 additions & 0 deletions drizzle/0000_add_vector_extension.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Custom SQL migration file, put you code below! --
CREATE EXTENSION IF NOT EXISTS vector;
19 changes: 19 additions & 0 deletions drizzle/0001_create_vector_data_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE TABLE IF NOT EXISTS "vector_data_text_embedding_3_small" (
"id" serial PRIMARY KEY NOT NULL,
"path" text NOT NULL,
"mtime" bigint NOT NULL,
"content" text NOT NULL,
"embedding" vector(1536),
"metadata" jsonb NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "vector_data_text_embedding_3_large" (
"id" serial PRIMARY KEY NOT NULL,
"path" text NOT NULL,
"mtime" bigint NOT NULL,
"content" text NOT NULL,
"embedding" vector(3072),
"metadata" jsonb NOT NULL
);
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "embeddingIndex_text_embedding_3_small" ON "vector_data_text_embedding_3_small" USING hnsw ("embedding" vector_cosine_ops);
glowingjade marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "8344dba7-b655-4009-9c56-894062c17ea6",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {},
"enums": {},
"schemas": {},
"views": {},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
128 changes: 128 additions & 0 deletions drizzle/meta/0001_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"id": "1084161a-8de5-4452-ba8b-6ffc3549d411",
"prevId": "8344dba7-b655-4009-9c56-894062c17ea6",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.vector_data_text_embedding_3_small": {
"name": "vector_data_text_embedding_3_small",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"path": {
"name": "path",
"type": "text",
"primaryKey": false,
"notNull": true
},
"mtime": {
"name": "mtime",
"type": "bigint",
"primaryKey": false,
"notNull": true
},
"content": {
"name": "content",
"type": "text",
"primaryKey": false,
"notNull": true
},
"embedding": {
"name": "embedding",
"type": "vector(1536)",
"primaryKey": false,
"notNull": false
},
"metadata": {
"name": "metadata",
"type": "jsonb",
"primaryKey": false,
"notNull": true
}
},
"indexes": {
"embeddingIndex_text_embedding_3_small": {
"name": "embeddingIndex_text_embedding_3_small",
"columns": [
{
"expression": "embedding",
"isExpression": false,
"asc": true,
"nulls": "last",
"opclass": "vector_cosine_ops"
}
],
"isUnique": false,
"concurrently": false,
"method": "hnsw",
"with": {}
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"public.vector_data_text_embedding_3_large": {
"name": "vector_data_text_embedding_3_large",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"path": {
"name": "path",
"type": "text",
"primaryKey": false,
"notNull": true
},
"mtime": {
"name": "mtime",
"type": "bigint",
"primaryKey": false,
"notNull": true
},
"content": {
"name": "content",
"type": "text",
"primaryKey": false,
"notNull": true
},
"embedding": {
"name": "embedding",
"type": "vector(3072)",
"primaryKey": false,
"notNull": false
},
"metadata": {
"name": "metadata",
"type": "jsonb",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"enums": {},
"schemas": {},
"sequences": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
20 changes: 20 additions & 0 deletions drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "7",
"dialect": "postgresql",
"entries": [
{
"idx": 0,
"version": "7",
"when": 1729509950412,
"tag": "0000_add_vector_extension",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1729509994653,
"tag": "0001_create_vector_data_tables",
"breakpoints": true
}
]
}
14 changes: 11 additions & 3 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'path'
import esbuild from 'esbuild'
import process from 'process'
import builtins from 'builtin-modules'
Expand All @@ -14,7 +15,7 @@ const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ['src/main.ts'], // Change this line
entryPoints: ['src/main.ts'],
bundle: true,
external: [
'obsidian',
Expand All @@ -33,12 +34,19 @@ const context = await esbuild.context({
...builtins,
],
format: 'cjs',
target: 'es2018',
define: {
'import.meta.url': 'import_meta_url',
process: '{}',
'process.env.NODE_ENV': JSON.stringify(prod ? 'production' : 'development'),
},
inject: [path.resolve('import-meta-url-shim.js')],
target: 'es2020',
logLevel: 'info',
sourcemap: prod ? false : 'inline',
treeShaking: true,
outfile: 'main.js', // Changed back to main.js
outfile: 'main.js',
minify: prod,
// logLevel: 'debug',
})

if (prod) {
Expand Down
7 changes: 7 additions & 0 deletions import-meta-url-shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const import_meta_url =
typeof document === 'undefined'
? require('url').pathToFileURL(__filename).href
: (document.currentScript && document.currentScript.src) ||
new URL('main.js', document.baseURI).href

export { import_meta_url }
Loading
Loading