mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-06-14 02:40:45 +08:00
fix(vector): harden runtime embedding sync
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
AuthorityHttpClient,
|
||||
AuthorityHttpError,
|
||||
} from "../runtime/authority-http-client.js";
|
||||
import { embedText } from "./embedding.js";
|
||||
import { embedBatch } from "./embedding.js";
|
||||
|
||||
export const AUTHORITY_VECTOR_MODE = "authority";
|
||||
export const AUTHORITY_VECTOR_SOURCE = "authority-trivium";
|
||||
@@ -15,6 +15,7 @@ const MAX_AUTHORITY_VECTOR_CHUNK_SIZE = 2000;
|
||||
const DEFAULT_AUTHORITY_PURGE_PAGE_SIZE = 200;
|
||||
const DEFAULT_AUTHORITY_PURGE_MAX_PAGES = 1000;
|
||||
const DEFAULT_AUTHORITY_EMBEDDING_BACKEND_SOURCE = "openai";
|
||||
const AUTHORITY_CONNECTION_PROBE_TEXTS = ["test connection", "runtime batch probe"];
|
||||
|
||||
function clampInteger(value, fallback, min, max) {
|
||||
const parsed = Number(value);
|
||||
@@ -942,9 +943,19 @@ export async function searchAuthorityTriviumNodes(graph, text, config = {}, opti
|
||||
}
|
||||
|
||||
export async function testAuthorityTriviumConnection(config = {}, options = {}) {
|
||||
const probeVector = await embedText("test connection", config, { isQuery: true });
|
||||
const probeVectors = await embedBatch(AUTHORITY_CONNECTION_PROBE_TEXTS, config, {
|
||||
isQuery: true,
|
||||
});
|
||||
const probeVector = probeVectors.find((vector) => vector && vector.length > 0);
|
||||
if (!probeVector || probeVector.length === 0) {
|
||||
return { success: false, dimensions: 0, error: "Embedding API 返回空结果" };
|
||||
return {
|
||||
success: false,
|
||||
dimensions: 0,
|
||||
error: "Embedding API 批量返回空结果",
|
||||
batchCapable: false,
|
||||
mode: AUTHORITY_VECTOR_MODE,
|
||||
source: AUTHORITY_VECTOR_SOURCE,
|
||||
};
|
||||
}
|
||||
const client = createAuthorityTriviumClient(config, options);
|
||||
await callClient(client, ["stat"], "stat", {
|
||||
@@ -952,5 +963,12 @@ export async function testAuthorityTriviumConnection(config = {}, options = {})
|
||||
collectionId: options.collectionId,
|
||||
chatId: options.chatId,
|
||||
});
|
||||
return { success: true, dimensions: probeVector.length, error: "" };
|
||||
return {
|
||||
success: true,
|
||||
dimensions: probeVector.length,
|
||||
error: "",
|
||||
batchCapable: true,
|
||||
mode: AUTHORITY_VECTOR_MODE,
|
||||
source: AUTHORITY_VECTOR_SOURCE,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user