Every bot file was chunked into bot_file_chunks and embedded into bot_file_vectors, and uploads kept their extracted text in media.text_content, which together took most of the database. Bot files are no longer indexed: bots find them by name or path with list_files and read them with read_file, and search_files, ingest_file and the files modal's re-read button are gone. Attachments keep no text; a reply reads a document from the file. Only knowledgebase documents keep text. The schema drops both tables and the ingest columns. At boot, dropStoredFileText removes what older versions stored (file jobs, upload text) and vacuums once much of the database is free. The media:prune-text script it replaces is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { AppData } from "@/src/data/app-data";
|
|
|
|
type Params = {
|
|
vector: number[];
|
|
/**
|
|
* Defaults to `AppData.EmbeddingDimensions`, the width of the fixed
|
|
* `knowledgebase_vectors` table.
|
|
*/
|
|
dimensions?: number;
|
|
};
|
|
|
|
/**
|
|
* Makes a provider's vector the width the vector table takes: cut when
|
|
* it's wider, padded with zeros when narrower, then normalized to unit
|
|
* length so cosine distance means the same for every model.
|
|
*/
|
|
export default function fitVectorDimensions({
|
|
vector,
|
|
dimensions = AppData.EmbeddingDimensions,
|
|
}: Params): Float32Array<ArrayBuffer> {
|
|
const out = new Float32Array(new ArrayBuffer(dimensions * 4));
|
|
const length = Math.min(vector.length, dimensions);
|
|
|
|
let sum = 0;
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
const value = Number(vector[i]) || 0;
|
|
|
|
out[i] = value;
|
|
sum += value * value;
|
|
}
|
|
|
|
/**
|
|
* A zero vector can't be normalized; leave it as zeros (it then
|
|
* matches nothing).
|
|
*/
|
|
const norm = Math.sqrt(sum);
|
|
|
|
if (norm > 0) {
|
|
for (let i = 0; i < dimensions; i++) {
|
|
out[i] = out[i]! / norm;
|
|
}
|
|
}
|
|
|
|
return out;
|
|
}
|