MCPcopy Create free account
hub / github.com/CopilotKit/aimock / VectorMock

Class VectorMock

src/vector-mock.ts:16–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14import { flattenHeaders, readBody } from "./helpers.js";
15
16export class VectorMock implements Mountable {
17 private collections: Map<string, VectorCollection> = new Map();
18 private queryHandlers: Map<string, QueryHandler> = new Map();
19 private server: http.Server | null = null;
20 private journal: Journal | null = null;
21 private registry: MetricsRegistry | null = null;
22 private options: VectorMockOptions;
23 private requestHandler: ReturnType<typeof createVectorRequestHandler>;
24
25 constructor(options?: VectorMockOptions) {
26 this.options = options ?? {};
27 this.requestHandler = this.buildHandler();
28 }
29
30 // ---- Configuration ----
31
32 addCollection(name: string, opts: { dimension: number }): this {
33 const collection: VectorCollection = {
34 name,
35 dimension: opts.dimension,
36 vectors: new Map(),
37 };
38 this.collections.set(name, collection);
39 this.requestHandler = this.buildHandler();
40 return this;
41 }
42
43 upsert(collection: string, vectors: VectorEntry[]): this {
44 let col = this.collections.get(collection);
45 if (!col) {
46 const dim = vectors.length > 0 ? vectors[0].values.length : 0;
47 col = { name: collection, dimension: dim, vectors: new Map() };
48 this.collections.set(collection, col);
49 }
50 for (const v of vectors) {
51 col.vectors.set(v.id, v);
52 }
53 this.requestHandler = this.buildHandler();
54 return this;
55 }
56
57 onQuery(
58 collection: string,
59 results: QueryResult[] | ((query: VectorQuery) => QueryResult[]),
60 ): this {
61 this.queryHandlers.set(collection, results);
62 this.requestHandler = this.buildHandler();
63 return this;
64 }
65
66 deleteCollection(name: string): this {
67 this.collections.delete(name);
68 this.queryHandlers.delete(name);
69 this.requestHandler = this.buildHandler();
70 return this;
71 }
72
73 // ---- Mountable interface ----

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…