Skip to content

Commit 05c50f4

Browse files
authored
Merge pull request #30 from twaugh/small-fixes
Small fixes: remove redundant code and deduplicate defaults
2 parents 1242bdf + 1366e4a commit 05c50f4

8 files changed

Lines changed: 22 additions & 28 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Search across all your Logseq blocks using text embeddings. Instead of matching exact keywords, semantic search finds blocks that are **conceptually similar** to your query.
44

5-
Blocks are embedded with their full context — page name, page properties, and parent block hierarchy — so searching for a page topic or parent heading surfaces relevant child blocks.
5+
Each block is embedded content-first, followed by its context — page name, page and block properties, and parent block hierarchy — so searching for a page topic or parent heading surfaces relevant child blocks.
66

77
## Requirements
88

@@ -89,6 +89,8 @@ Semantic search matches meaning, not exact words. To get the best results:
8989
| Batch Size | `50` | Number of texts per API request |
9090
| Top K Results | `20` | Maximum number of search results |
9191
| Auto-index on Load | `true` | Automatically index when the graph loads |
92+
| Page Properties | `tags, alias, category, type, ...` | Comma-separated page properties to include in embedding context |
93+
| Block Properties | `type, status, priority, tags, ...` | Comma-separated block properties to include in embedding text |
9294

9395
## Support
9496

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "logseq-plugin-semantic-search",
3-
"version": "0.1.6",
3+
"version": "0.2.0",
44
"description": "Search your Logseq notes by meaning, not just keywords",
55
"main": "dist/index.html",
66
"scripts": {

src/indexer.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
getMetadata,
1010
setMetadata,
1111
getEmbeddingCount,
12-
invalidateEmbeddingCache,
1312
} from "./storage";
1413
import { getSettings } from "./settings";
1514

@@ -407,9 +406,6 @@ export async function indexBlocks(
407406
await setMetadata("blockCount", count);
408407
await setMetadata("lastIndexed", Date.now());
409408

410-
// Ensure search cache is fresh after indexing
411-
invalidateEmbeddingCache();
412-
413409
if (!abort.signal.aborted && total > 0) {
414410
logseq.UI.showMsg(`Indexed ${total} blocks`);
415411
}

src/main.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ async function main() {
5555
}
5656
});
5757

58+
async function syncGraphName(): Promise<void> {
59+
const graph = await logseq.App.getCurrentGraph();
60+
if (graph?.name) setGraphName(graph.name);
61+
}
62+
5863
// Auto-index on load
5964
const settings = getSettings();
6065
if (settings.autoIndexOnLoad) {
6166
// Delay to let Logseq finish loading
6267
setTimeout(async () => {
6368
try {
64-
const graph = await logseq.App.getCurrentGraph();
65-
if (graph?.name) setGraphName(graph.name);
69+
await syncGraphName();
6670
await indexBlocks();
6771
} catch (err) {
6872
console.error("Auto-indexing failed:", err);
@@ -72,8 +76,7 @@ async function main() {
7276

7377
// Re-index on graph change
7478
logseq.App.onCurrentGraphChanged(async () => {
75-
const graph = await logseq.App.getCurrentGraph();
76-
if (graph?.name) setGraphName(graph.name);
79+
await syncGraphName();
7780
const s = getSettings();
7881
if (s.autoIndexOnLoad) {
7982
setTimeout(() => {

src/settings.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,13 @@ export interface PluginSettings {
9393
blockProperties: string;
9494
}
9595

96+
const settingsDefaults: PluginSettings = Object.fromEntries(
97+
settingsSchema
98+
.filter((s) => s.type !== "heading")
99+
.map((s) => [s.key, s.default]),
100+
) as unknown as PluginSettings;
101+
96102
export function getSettings(): PluginSettings {
97103
const s = logseq.settings as Partial<PluginSettings> | undefined;
98-
return {
99-
apiEndpoint: s?.apiEndpoint ?? "http://localhost:11434",
100-
apiFormat: s?.apiFormat ?? "ollama",
101-
embeddingModel: s?.embeddingModel ?? "nomic-embed-text",
102-
batchSize: s?.batchSize ?? 50,
103-
topK: s?.topK ?? 20,
104-
autoIndexOnLoad: s?.autoIndexOnLoad ?? true,
105-
pageProperties: s?.pageProperties ?? "tags, alias, category, type, description, summary, author, topic, area, project, status, priority, platform",
106-
blockProperties: s?.blockProperties ?? "type, status, priority, tags, source, url, author",
107-
};
104+
return { ...settingsDefaults, ...s };
108105
}

src/storage.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ export function invalidateEmbeddingCache(): void {
122122
embeddingCache = null;
123123
}
124124

125-
export function evictEmbeddingCache(): void {
126-
embeddingCache = null;
127-
}
128-
129125
export async function deleteEmbeddings(blockIds: string[]): Promise<void> {
130126
if (blockIds.length === 0) return;
131127
const db = await openDB();

src/ui.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { debounce } from "./utils";
22
import { embedTexts } from "./embeddings";
3-
import { getCachedEmbeddings, getEmbeddingCount, evictEmbeddingCache } from "./storage";
3+
import { getCachedEmbeddings, getEmbeddingCount, invalidateEmbeddingCache } from "./storage";
44
import { searchEmbeddings, type SearchResult } from "./search";
55
import { indexBlocks, indexingState, acquireSearchPriority, releaseSearchPriority } from "./indexer";
66
import { getSettings } from "./settings";
@@ -196,7 +196,7 @@ function hideModal(): void {
196196
// Evict embedding cache after idle period
197197
if (evictTimer) clearTimeout(evictTimer);
198198
evictTimer = setTimeout(() => {
199-
evictEmbeddingCache();
199+
invalidateEmbeddingCache();
200200
evictTimer = undefined;
201201
}, CACHE_EVICT_MS);
202202
}
@@ -427,7 +427,7 @@ export function showModal(): void {
427427
evictTimer = undefined;
428428
}
429429
// Invalidate cache so first search loads fresh from IDB
430-
evictEmbeddingCache();
430+
invalidateEmbeddingCache();
431431
clearResults();
432432
logseq.showMainUI();
433433
if (indexingState.status === "idle") {

styles/search-modal.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
background: var(--ls-primary-background-color, #fff);
1717
color: var(--ls-primary-text-color, #333);
1818
border-radius: 8px;
19-
width: 600px;
19+
width: 900px;
2020
max-width: 90vw;
2121
max-height: 70vh;
2222
display: flex;

0 commit comments

Comments
 (0)