Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

feat: separate embedding config — independent endpoint, API key, model

nash_su6821b4493a4c
diff --git a/src/components/settings/settings-view.tsx b/src/components/settings/settings-view.tsx
index 82c62db7..d55ed4e1 100644
--- a/src/components/settings/settings-view.tsx
+++ b/src/components/settings/settings-view.tsx
@@ -43,6 +43,8 @@ export function SettingsView() {
const [searchProvider, setSearchProvider] = useState(searchApiConfig.provider)
const [searchApiKey, setSearchApiKey] = useState(searchApiConfig.apiKey)
const [embeddingEnabled, setEmbeddingEnabled] = useState(embeddingConfig.enabled)
+ const [embeddingEndpoint, setEmbeddingEndpoint] = useState(embeddingConfig.endpoint)
+ const [embeddingApiKey, setEmbeddingApiKey] = useState(embeddingConfig.apiKey)
const [embeddingModel, setEmbeddingModel] = useState(embeddingConfig.model)
const [saved, setSaved] = useState(false)
const [currentLang, setCurrentLang] = useState(i18n.language)
@@ -66,7 +68,7 @@ export function SettingsView() {
const { saveLlmConfig, saveSearchApiConfig, saveEmbeddingConfig } = await import("@/lib/project-store")
const newConfig = { provider, apiKey, model, ollamaUrl, customEndpoint, maxContextSize }
const newSearchConfig = { provider: searchProvider, apiKey: searchApiKey }
- const newEmbeddingConfig = { enabled: embeddingEnabled, model: embeddingModel }
+ const newEmbeddingConfig = { enabled: embeddingEnabled, endpoint: embeddingEndpoint, apiKey: embeddingApiKey, model: embeddingModel }
setSearchApiConfig(newSearchConfig)
await saveSearchApiConfig(newSearchConfig)
setEmbeddingConfig(newEmbeddingConfig)
@@ -292,15 +294,34 @@ export function SettingsView() {
Enable semantic search using embeddings. Uses the same LLM provider endpoint. Improves search quality for synonym matching and cross-domain discovery.
</p>
{embeddingEnabled && (
- <div className="space-y-2">
- <Label>Embedding Model</Label>
- <Input
- value={embeddingModel}
- onChange={(e) => setEmbeddingModel(e.target.value)}
- placeholder="e.g. text-embedding-3-small, nomic-embed-text"
- />
+ <div className="space-y-3">
+ <div className="space-y-2">
+ <Label>Endpoint</Label>
+ <Input
+ value={embeddingEndpoint}
+ onChange={(e) => setEmbeddingEndpoint(e.target.value)}
+ placeholder="e.g. http://127.0.0.1:1234/v1/embeddings"
+ />
+ </div>
+ <div className="space-y-2">
+ <Label>API Key (optional)</Label>
+ <Input
+ type="password"
+ value={embeddingApiKey}
+ onChange={(e) => setEmbeddingApiKey(e.target.value)}
+ placeholder="Leave empty for local models"
+ />
+ </div>
+ <div className="space-y-2">
+ <Label>Model</Label>
+ <Input
+ value={embeddingModel}
+ onChange={(e) => setEmbeddingModel(e.target.value)}
+ placeholder="e.g. text-embedding-qwen3-embedding-0.6b"
+ />
+ </div>
<p className="text-xs text-muted-foreground">
- The embedding model name supported by your LLM provider.
+ Embedding service can be different from the chat LLM. Supports any OpenAI-compatible /v1/embeddings endpoint.
</p>
</div>
)}
diff --git a/src/lib/embedding.ts b/src/lib/embedding.ts
index 81aeb753..983c4cd1 100644
--- a/src/lib/embedding.ts
+++ b/src/lib/embedding.ts
@@ -1,46 +1,26 @@
import { readFile, listDirectory } from "@/commands/fs"
import { invoke } from "@tauri-apps/api/core"
-import type { LlmConfig, EmbeddingConfig } from "@/stores/wiki-store"
+import type { EmbeddingConfig } from "@/stores/wiki-store"
import type { FileNode } from "@/types/wiki"
import { normalizePath } from "@/lib/path-utils"
// ── Embedding API ─────────────────────────────────────────────────────────
-function getEmbeddingEndpoint(llmConfig: LlmConfig): string {
- switch (llmConfig.provider) {
- case "openai":
- return "https://api.openai.com/v1/embeddings"
- case "ollama":
- return `${llmConfig.ollamaUrl}/v1/embeddings`
- case "custom":
- return llmConfig.customEndpoint.replace(/\/chat\/completions\/?$/, "/embeddings")
- default:
- return llmConfig.customEndpoint
- ? llmConfig.customEndpoint.replace(/\/chat\/completions\/?$/, "/embeddings")
- : ""
- }
-}
-
-function getAuthHeaders(llmConfig: LlmConfig): Record<string, string> {
- const headers: Record<string, string> = { "Content-Type": "application/json" }
- if (llmConfig.apiKey) {
- headers["Authorization"] = `Bearer ${llmConfig.apiKey}`
- }
- return headers
-}
-
async function fetchEmbedding(
text: string,
- llmConfig: LlmConfig,
embeddingConfig: EmbeddingConfig,
): Promise<number[] | null> {
- const endpoint = getEmbeddingEndpoint(llmConfig)
- if (!endpoint) return null
+ if (!embeddingConfig.endpoint) return null
+
+ const headers: Record<string, string> = { "Content-Type": "application/json" }
+ if (embeddingConfig.apiKey) {
+ headers["Authorization"] = `Bearer ${embeddingConfig.apiKey}`
+ }
try {
- const resp = await fetch(endpoint, {
+ const resp = await fetch(embeddingConfig.endpoint, {
method: "POST",
- headers: getAuthHeaders(llmConfig),
+ headers,
body: JSON.stringify({
model: embeddingConfig.model,
input: text.slice(0, 2000),
@@ -96,14 +76,13 @@ export async function embedPage(
pageId: string,
title: string,
content: string,
- llmConfig: LlmConfig,
embeddingConfig: EmbeddingConfig,
): Promise<void> {
if (!embeddingConfig.enabled || !embeddingConfig.model) return
const t0 = performance.now()
const text = `${title}\n${content.slice(0, 1500)}`
- const emb = await fetchEmbedding(text, llmConfig, embeddingConfig)
+ const emb = await fetchEmbedding(text, embeddingConfig)
if (emb) {
await vectorUpsert(projectPath, pageId, emb)
console.log(`[Embedding] Indexed "${pageId}" (${emb.length}d) in ${Math.round(performance.now() - t0)}ms`)
@@ -118,7 +97,6 @@ export async function embedPage(
*/
export async function embedAllPages(
projectPath: string,
- llmConfig: LlmConfig,
embeddingConfig: EmbeddingConfig,
onProgress?: (done: number, total: number) => void,
): Promise<number> {
@@ -156,7 +134,7 @@ export async function embedAllPages(
const title = titleMatch ? titleMatch[1].trim() : file.id
const text = `${title}\n${content.slice(0, 1500)}`
- const emb = await fetchEmbedding(text, llmConfig, embeddingConfig)
+ const emb = await fetchEmbedding(text, embeddingConfig)
if (emb) {
await vectorUpsert(pp, file.id, emb)
}
@@ -178,7 +156,6 @@ export async function embedAllPages(
export async function searchByEmbedding(
projectPath: string,
query: string,
- llmConfig: LlmConfig,
embeddingConfig: EmbeddingConfig,
topK: number = 10,
): Promise<Array<{ id: string; score: number }>> {
diff --git a/src/lib/ingest.ts b/src/lib/ingest.ts
index 48053ee2..64cf0569 100644
--- a/src/lib/ingest.ts
+++ b/src/lib/ingest.ts
@@ -185,7 +185,6 @@ export async function autoIngest(
if (embCfg.enabled && embCfg.model && writtenPaths.length > 0) {
try {
const { embedPage } = await import("@/lib/embedding")
- const llmCfg = useWikiStore.getState().llmConfig
for (const wpath of writtenPaths) {
const pageId = wpath.split("/").pop()?.replace(/\.md$/, "") ?? ""
if (!pageId || ["index", "log", "overview"].includes(pageId)) continue
@@ -193,7 +192,7 @@ export async function autoIngest(
const content = await readFile(`${pp}/${wpath}`)
const titleMatch = content.match(/^---\n[\s\S]*?^title:\s*["']?(.+?)["']?\s*$/m)
const title = titleMatch ? titleMatch[1].trim() : pageId
- await embedPage(pp, pageId, title, content, llmCfg, embCfg)
+ await embedPage(pp, pageId, title, content, embCfg)
} catch {
// non-critical
}
diff --git a/src/lib/search.ts b/src/lib/search.ts
index 04da29de..c44c6ca0 100644
--- a/src/lib/search.ts
+++ b/src/lib/search.ts
@@ -147,8 +147,7 @@ export async function searchWiki(
if (embCfg.enabled && embCfg.model) {
const t0 = performance.now()
const { searchByEmbedding } = await import("@/lib/embedding")
- const llmCfg = useWikiStore.getState().llmConfig
- const vectorResults = await searchByEmbedding(pp, query, llmCfg, embCfg, 10)
+ const vectorResults = await searchByEmbedding(pp, query, embCfg, 10)
const vectorMs = Math.round(performance.now() - t0)
console.log(
diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.ts
index 8f0add0f..c1460531 100644
--- a/src/stores/wiki-store.ts
+++ b/src/stores/wiki-store.ts
@@ -17,6 +17,8 @@ interface SearchApiConfig {
interface EmbeddingConfig {
enabled: boolean
+ endpoint: string // e.g. "http://127.0.0.1:1234/v1/embeddings"
+ apiKey: string
model: string // e.g. "text-embedding-qwen3-embedding-0.6b"
}
@@ -75,6 +77,8 @@ export const useWikiStore = create<WikiState>((set) => ({
embeddingConfig: {
enabled: false,
+ endpoint: "",
+ apiKey: "",
model: "",
},