mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-07 18:42:25 +00:00
refactor(memory): drop unused host-sdk helpers
This commit is contained in:
@@ -22,10 +22,6 @@ export type LocalEmbeddingWorkerFailureError = Error & {
|
||||
signal?: NodeJS.Signals | null;
|
||||
};
|
||||
|
||||
const LOCAL_EMBEDDING_WORKER_FAILURE_CODES = new Set<string>(
|
||||
Object.values(LOCAL_EMBEDDING_WORKER_ERROR_CODES),
|
||||
);
|
||||
|
||||
/** Create a local embedding worker failure with stable metadata fields. */
|
||||
export function createLocalEmbeddingWorkerFailureError(params: {
|
||||
message: string;
|
||||
@@ -43,13 +39,3 @@ export function createLocalEmbeddingWorkerFailureError(params: {
|
||||
...(params.cause !== undefined ? { cause: params.cause } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Narrow unknown errors to local embedding worker lifecycle failures. */
|
||||
export function isLocalEmbeddingWorkerFailure(
|
||||
err: unknown,
|
||||
): err is LocalEmbeddingWorkerFailureError {
|
||||
return (
|
||||
err instanceof Error &&
|
||||
LOCAL_EMBEDDING_WORKER_FAILURE_CODES.has(String((err as { code?: unknown }).code))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Memory Host SDK tests cover query expansion behavior.
|
||||
// Memory Host SDK tests cover query keyword extraction behavior.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { expandQueryForFts, extractKeywords } from "./query-expansion.js";
|
||||
import { extractKeywords } from "./query-expansion.js";
|
||||
|
||||
describe("extractKeywords", () => {
|
||||
it("extracts keywords from English conversational query", () => {
|
||||
@@ -182,32 +182,3 @@ describe("extractKeywords", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("expandQueryForFts", () => {
|
||||
it("returns original query and extracted keywords", () => {
|
||||
const result = expandQueryForFts("that API we discussed");
|
||||
expect(result).toStrictEqual({
|
||||
original: "that API we discussed",
|
||||
keywords: ["api", "discussed"],
|
||||
expanded: "that API we discussed OR api OR discussed",
|
||||
});
|
||||
});
|
||||
|
||||
it("builds expanded OR query for FTS", () => {
|
||||
const result = expandQueryForFts("the solution for bugs");
|
||||
expect(result).toStrictEqual({
|
||||
original: "the solution for bugs",
|
||||
keywords: ["solution", "bugs"],
|
||||
expanded: "the solution for bugs OR solution OR bugs",
|
||||
});
|
||||
});
|
||||
|
||||
it("returns original query when no keywords extracted", () => {
|
||||
const result = expandQueryForFts("the");
|
||||
expect(result).toStrictEqual({
|
||||
original: "the",
|
||||
keywords: [],
|
||||
expanded: "the",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -774,28 +774,3 @@ export function extractKeywords(
|
||||
|
||||
return keywords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand a query for FTS search.
|
||||
* Returns both the original query and extracted keywords for OR-matching.
|
||||
*
|
||||
* @param query - User's original query
|
||||
* @returns Object with original query and extracted keywords
|
||||
*/
|
||||
export function expandQueryForFts(
|
||||
query: string,
|
||||
opts?: { ftsTokenizer?: "unicode61" | "trigram" },
|
||||
): {
|
||||
original: string;
|
||||
keywords: string[];
|
||||
expanded: string;
|
||||
} {
|
||||
const original = query.trim();
|
||||
const keywords = extractKeywords(original, opts);
|
||||
|
||||
// Build expanded query: original terms OR extracted keywords
|
||||
// This ensures both exact matches and keyword matches are found
|
||||
const expanded = keywords.length > 0 ? `${original} OR ${keywords.join(" OR ")}` : original;
|
||||
|
||||
return { original, keywords, expanded };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user