This repository was archived by the owner on Jun 24, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 149
feat(ocr): add ocr #2254
Closed
Closed
feat(ocr): add ocr #2254
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c4a0219
feat(ocr): add unit tests, resolve double sent headers, and fix the w…
perfectra1n 33a5492
fix(package): referenced wrong tesseract.js lol
perfectra1n 864543e
feat(ocr): drop confidence down a little bit
perfectra1n a4adc51
fix(unit): resolve typecheck errors
perfectra1n f135622
feat(unit): ocr unit tests almost pass
perfectra1n d20b3d8
feat(unit): ocr tests almost pass...
perfectra1n 80a9182
feat(unit): ocr tests almost pass...
perfectra1n 7868ebe
fix(unit): also fix broken llm test
perfectra1n 09196c0
fix(ocr): obviously don't need this migration file anymore
perfectra1n 4b5e8d3
Update playwright.yml
perfectra1n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,66 @@ | |
|
|
||
| // Migrations should be kept in descending order, so the latest migration is first. | ||
| const MIGRATIONS: (SqlMigration | JsMigration)[] = [ | ||
| // Add OCR results table for storing extracted text from images | ||
| { | ||
| version: 233, | ||
| sql: /*sql*/`\ | ||
| -- Create OCR results table to store extracted text from images | ||
| CREATE TABLE IF NOT EXISTS ocr_results ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| entity_id TEXT NOT NULL, | ||
| entity_type TEXT NOT NULL DEFAULT 'note', | ||
| extracted_text TEXT NOT NULL, | ||
| confidence REAL NOT NULL, | ||
| language TEXT NOT NULL DEFAULT 'eng', | ||
| extracted_at TEXT NOT NULL, | ||
| created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| UNIQUE(entity_id, entity_type) | ||
| ); | ||
| -- Create indexes for better search performance | ||
| CREATE INDEX IF NOT EXISTS idx_ocr_results_entity | ||
| ON ocr_results (entity_id, entity_type); | ||
| CREATE INDEX IF NOT EXISTS idx_ocr_results_text | ||
| ON ocr_results (extracted_text); | ||
| CREATE INDEX IF NOT EXISTS idx_ocr_results_confidence | ||
| ON ocr_results (confidence); | ||
| -- Create full-text search index for extracted text | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's interesting but I suppose this creates additional complexity. We don't yet have full-text search for note content. So I think we should try to find a solution (doesn't have to be in the same PR) that allows full text search on the entire |
||
| CREATE VIRTUAL TABLE IF NOT EXISTS ocr_results_fts USING fts5( | ||
| entity_id UNINDEXED, | ||
| entity_type UNINDEXED, | ||
| extracted_text, | ||
| content='ocr_results', | ||
| content_rowid='id' | ||
| ); | ||
| -- Create triggers to keep FTS table in sync | ||
| CREATE TRIGGER IF NOT EXISTS ocr_results_fts_insert | ||
| AFTER INSERT ON ocr_results | ||
| BEGIN | ||
| INSERT INTO ocr_results_fts(rowid, entity_id, entity_type, extracted_text) | ||
| VALUES (new.id, new.entity_id, new.entity_type, new.extracted_text); | ||
| END; | ||
| CREATE TRIGGER IF NOT EXISTS ocr_results_fts_update | ||
| AFTER UPDATE ON ocr_results | ||
| BEGIN | ||
| UPDATE ocr_results_fts | ||
| SET extracted_text = new.extracted_text | ||
| WHERE rowid = new.id; | ||
| END; | ||
| CREATE TRIGGER IF NOT EXISTS ocr_results_fts_delete | ||
| AFTER DELETE ON ocr_results | ||
| BEGIN | ||
| DELETE FROM ocr_results_fts WHERE rowid = old.id; | ||
| END; | ||
| ` | ||
| }, | ||
| // Remove embedding tables since LLM embedding functionality has been removed | ||
| { | ||
| version: 232, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of storing the results in a separate table (that is not synced yet), how about simply storing the results in an attachment?
This:
role.blobsstructure that is shared with notes and attachments.The only problem is with image-attachments, since we can't have attachments for attachments.
Maybe we have to think a bit deeper, to see if it can be further reused on things other than OCR. Perhaps one way would be to have "different representations" for blobs, such as their binary data (e.g. images, files), but also a textual representation that can be used not only for images but also OCR, LLM, etc.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You definitely have the "whole picture" in mind - so do you think it's best to bite the bullet and create some new table/object that can be used/reused for objects (or even a more obscure "object", whatever that may be in the future) such as these, or do we just use something like a "sibling attachment" for now as you suggested?