@semiont/vectors 0.5.4 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-2XM7KF3W.js → chunk-IWHPVMXW.js} +2 -4
- package/dist/{chunk-2XM7KF3W.js.map → chunk-IWHPVMXW.js.map} +1 -1
- package/dist/index.d.ts +217 -21
- package/dist/index.js +2 -2
- package/dist/qdrant-YF2TKFCE.js +7 -0
- package/package.json +14 -6
- package/dist/chunking.d.ts +0 -20
- package/dist/chunking.d.ts.map +0 -1
- package/dist/embedding/factory.d.ts +0 -13
- package/dist/embedding/factory.d.ts.map +0 -1
- package/dist/embedding/interface.d.ts +0 -17
- package/dist/embedding/interface.d.ts.map +0 -1
- package/dist/embedding/ollama.d.ts +0 -20
- package/dist/embedding/ollama.d.ts.map +0 -1
- package/dist/embedding/voyage.d.ts +0 -21
- package/dist/embedding/voyage.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/qdrant-WGOBIU6H.js +0 -7
- package/dist/store/factory.d.ts +0 -15
- package/dist/store/factory.d.ts.map +0 -1
- package/dist/store/interface.d.ts +0 -51
- package/dist/store/interface.d.ts.map +0 -1
- package/dist/store/memory.d.ts +0 -26
- package/dist/store/memory.d.ts.map +0 -1
- package/dist/store/qdrant.d.ts +0 -33
- package/dist/store/qdrant.d.ts.map +0 -1
- /package/dist/{qdrant-WGOBIU6H.js.map → qdrant-YF2TKFCE.js.map} +0 -0
|
@@ -117,9 +117,7 @@ var QdrantVectorStore = class {
|
|
|
117
117
|
if (!filter) return null;
|
|
118
118
|
const must = [];
|
|
119
119
|
if (filter.entityTypes && filter.entityTypes.length > 0) {
|
|
120
|
-
|
|
121
|
-
must.push({ key: "entityTypes", match: { value: et } });
|
|
122
|
-
}
|
|
120
|
+
must.push({ key: "entityTypes", match: { any: filter.entityTypes } });
|
|
123
121
|
}
|
|
124
122
|
if (filter.resourceId) {
|
|
125
123
|
must.push({ key: "resourceId", match: { value: String(filter.resourceId) } });
|
|
@@ -142,4 +140,4 @@ var QdrantVectorStore = class {
|
|
|
142
140
|
export {
|
|
143
141
|
QdrantVectorStore
|
|
144
142
|
};
|
|
145
|
-
//# sourceMappingURL=chunk-
|
|
143
|
+
//# sourceMappingURL=chunk-IWHPVMXW.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store/qdrant.ts"],"sourcesContent":["/**\n * Qdrant VectorStore Implementation\n *\n * Uses the Qdrant REST API via @qdrant/js-client-rest.\n * Manages two collections: 'resources' and 'annotations'.\n */\n\nimport { createHash } from 'crypto';\nimport type { ResourceId, AnnotationId } from '@semiont/core';\nimport type { VectorStore, EmbeddingChunk, AnnotationPayload, VectorSearchResult, SearchOptions } from './interface';\n\n/**\n * Generate a deterministic UUID v5-style ID from an arbitrary string.\n * Qdrant requires point IDs to be UUIDs or unsigned integers.\n */\nfunction toQdrantId(input: string): string {\n const hex = createHash('md5').update(input).digest('hex');\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;\n}\n\nexport interface QdrantConfig {\n host: string;\n port: number;\n dimensions: number;\n}\n\nexport class QdrantVectorStore implements VectorStore {\n private client: any = null;\n private connected = false;\n private config: QdrantConfig;\n\n constructor(config: QdrantConfig) {\n this.config = config;\n }\n\n async connect(): Promise<void> {\n const { QdrantClient } = await import('@qdrant/js-client-rest');\n this.client = new QdrantClient({\n host: this.config.host,\n port: this.config.port,\n });\n\n // Ensure collections exist\n await this.ensureCollection('resources', this.config.dimensions);\n await this.ensureCollection('annotations', this.config.dimensions);\n this.connected = true;\n }\n\n async disconnect(): Promise<void> {\n this.client = null;\n this.connected = false;\n }\n\n async clearAll(): Promise<void> {\n try { await this.client.deleteCollection('resources'); } catch { /* may not exist */ }\n try { await this.client.deleteCollection('annotations'); } catch { /* may not exist */ }\n await this.ensureCollection('resources', this.config.dimensions);\n await this.ensureCollection('annotations', this.config.dimensions);\n }\n\n isConnected(): boolean {\n return this.connected;\n }\n\n private async ensureCollection(name: string, dimensions: number): Promise<void> {\n try {\n await this.client.getCollection(name);\n } catch {\n await this.client.createCollection(name, {\n vectors: { size: dimensions, distance: 'Cosine' },\n });\n }\n }\n\n async upsertResourceVectors(resourceId: ResourceId, chunks: EmbeddingChunk[]): Promise<void> {\n if (chunks.length === 0) return;\n\n const points = chunks.map((chunk) => ({\n id: toQdrantId(`${resourceId}-${chunk.chunkIndex}`),\n vector: chunk.embedding,\n payload: {\n resourceId: String(resourceId),\n chunkIndex: chunk.chunkIndex,\n text: chunk.text,\n },\n }));\n\n await this.client.upsert('resources', { points });\n }\n\n async upsertAnnotationVector(\n annotationId: AnnotationId,\n embedding: number[],\n payload: AnnotationPayload\n ): Promise<void> {\n await this.client.upsert('annotations', {\n points: [{\n id: toQdrantId(String(annotationId)),\n vector: embedding,\n payload: {\n annotationId: String(payload.annotationId),\n resourceId: String(payload.resourceId),\n motivation: payload.motivation,\n entityTypes: payload.entityTypes,\n text: payload.exactText,\n },\n }],\n });\n }\n\n async deleteResourceVectors(resourceId: ResourceId): Promise<void> {\n await this.client.delete('resources', {\n filter: {\n must: [{ key: 'resourceId', match: { value: String(resourceId) } }],\n },\n });\n }\n\n async deleteAnnotationVector(annotationId: AnnotationId): Promise<void> {\n await this.client.delete('annotations', {\n points: [toQdrantId(String(annotationId))],\n });\n }\n\n async searchResources(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]> {\n return this.search('resources', embedding, opts);\n }\n\n async searchAnnotations(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]> {\n return this.search('annotations', embedding, opts);\n }\n\n private async search(collection: string, embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]> {\n const filter = this.buildFilter(opts.filter);\n\n const results = await this.client.search(collection, {\n vector: embedding,\n limit: opts.limit,\n score_threshold: opts.scoreThreshold,\n filter: filter || undefined,\n with_payload: true,\n });\n\n return results.map((r: any) => ({\n id: String(r.id),\n score: r.score,\n resourceId: r.payload.resourceId as ResourceId,\n annotationId: r.payload.annotationId as AnnotationId | undefined,\n text: r.payload.text as string,\n entityTypes: r.payload.entityTypes as string[] | undefined,\n }));\n }\n\n private buildFilter(filter?: SearchOptions['filter']): any | null {\n if (!filter) return null;\n\n const must: any[] = [];\n\n if (filter.entityTypes && filter.entityTypes.length > 0) {\n
|
|
1
|
+
{"version":3,"sources":["../src/store/qdrant.ts"],"sourcesContent":["/**\n * Qdrant VectorStore Implementation\n *\n * Uses the Qdrant REST API via @qdrant/js-client-rest.\n * Manages two collections: 'resources' and 'annotations'.\n */\n\nimport { createHash } from 'crypto';\nimport type { ResourceId, AnnotationId } from '@semiont/core';\nimport type { VectorStore, EmbeddingChunk, AnnotationPayload, VectorSearchResult, SearchOptions } from './interface';\n\n/**\n * Generate a deterministic UUID v5-style ID from an arbitrary string.\n * Qdrant requires point IDs to be UUIDs or unsigned integers.\n */\nfunction toQdrantId(input: string): string {\n const hex = createHash('md5').update(input).digest('hex');\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;\n}\n\nexport interface QdrantConfig {\n host: string;\n port: number;\n dimensions: number;\n}\n\nexport class QdrantVectorStore implements VectorStore {\n private client: any = null;\n private connected = false;\n private config: QdrantConfig;\n\n constructor(config: QdrantConfig) {\n this.config = config;\n }\n\n async connect(): Promise<void> {\n const { QdrantClient } = await import('@qdrant/js-client-rest');\n this.client = new QdrantClient({\n host: this.config.host,\n port: this.config.port,\n });\n\n // Ensure collections exist\n await this.ensureCollection('resources', this.config.dimensions);\n await this.ensureCollection('annotations', this.config.dimensions);\n this.connected = true;\n }\n\n async disconnect(): Promise<void> {\n this.client = null;\n this.connected = false;\n }\n\n async clearAll(): Promise<void> {\n try { await this.client.deleteCollection('resources'); } catch { /* may not exist */ }\n try { await this.client.deleteCollection('annotations'); } catch { /* may not exist */ }\n await this.ensureCollection('resources', this.config.dimensions);\n await this.ensureCollection('annotations', this.config.dimensions);\n }\n\n isConnected(): boolean {\n return this.connected;\n }\n\n private async ensureCollection(name: string, dimensions: number): Promise<void> {\n try {\n await this.client.getCollection(name);\n } catch {\n await this.client.createCollection(name, {\n vectors: { size: dimensions, distance: 'Cosine' },\n });\n }\n }\n\n async upsertResourceVectors(resourceId: ResourceId, chunks: EmbeddingChunk[]): Promise<void> {\n if (chunks.length === 0) return;\n\n const points = chunks.map((chunk) => ({\n id: toQdrantId(`${resourceId}-${chunk.chunkIndex}`),\n vector: chunk.embedding,\n payload: {\n resourceId: String(resourceId),\n chunkIndex: chunk.chunkIndex,\n text: chunk.text,\n },\n }));\n\n await this.client.upsert('resources', { points });\n }\n\n async upsertAnnotationVector(\n annotationId: AnnotationId,\n embedding: number[],\n payload: AnnotationPayload\n ): Promise<void> {\n await this.client.upsert('annotations', {\n points: [{\n id: toQdrantId(String(annotationId)),\n vector: embedding,\n payload: {\n annotationId: String(payload.annotationId),\n resourceId: String(payload.resourceId),\n motivation: payload.motivation,\n entityTypes: payload.entityTypes,\n text: payload.exactText,\n },\n }],\n });\n }\n\n async deleteResourceVectors(resourceId: ResourceId): Promise<void> {\n await this.client.delete('resources', {\n filter: {\n must: [{ key: 'resourceId', match: { value: String(resourceId) } }],\n },\n });\n }\n\n async deleteAnnotationVector(annotationId: AnnotationId): Promise<void> {\n await this.client.delete('annotations', {\n points: [toQdrantId(String(annotationId))],\n });\n }\n\n async searchResources(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]> {\n return this.search('resources', embedding, opts);\n }\n\n async searchAnnotations(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]> {\n return this.search('annotations', embedding, opts);\n }\n\n private async search(collection: string, embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]> {\n const filter = this.buildFilter(opts.filter);\n\n const results = await this.client.search(collection, {\n vector: embedding,\n limit: opts.limit,\n score_threshold: opts.scoreThreshold,\n filter: filter || undefined,\n with_payload: true,\n });\n\n return results.map((r: any) => ({\n id: String(r.id),\n score: r.score,\n resourceId: r.payload.resourceId as ResourceId,\n annotationId: r.payload.annotationId as AnnotationId | undefined,\n text: r.payload.text as string,\n entityTypes: r.payload.entityTypes as string[] | undefined,\n }));\n }\n\n private buildFilter(filter?: SearchOptions['filter']): any | null {\n if (!filter) return null;\n\n const must: any[] = [];\n\n if (filter.entityTypes && filter.entityTypes.length > 0) {\n // any-of: match payloads whose `entityTypes` array contains at least one\n // of the requested types. Matches the memory store's `some(t => ...)`\n // semantics; pushing one `must` clause per type would mean all-of.\n must.push({ key: 'entityTypes', match: { any: filter.entityTypes } });\n }\n\n if (filter.resourceId) {\n must.push({ key: 'resourceId', match: { value: String(filter.resourceId) } });\n }\n\n if (filter.motivation) {\n must.push({ key: 'motivation', match: { value: filter.motivation } });\n }\n\n const must_not: any[] = [];\n\n if (filter.excludeResourceId) {\n must_not.push({ key: 'resourceId', match: { value: String(filter.excludeResourceId) } });\n }\n\n if (must.length === 0 && must_not.length === 0) return null;\n\n return {\n ...(must.length > 0 ? { must } : {}),\n ...(must_not.length > 0 ? { must_not } : {}),\n };\n }\n}\n"],"mappings":";AAOA,SAAS,kBAAkB;AAQ3B,SAAS,WAAW,OAAuB;AACzC,QAAM,MAAM,WAAW,KAAK,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AACxD,SAAO,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC;AAC9G;AAQO,IAAM,oBAAN,MAA+C;AAAA,EAC5C,SAAc;AAAA,EACd,YAAY;AAAA,EACZ;AAAA,EAER,YAAY,QAAsB;AAChC,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAM,UAAyB;AAC7B,UAAM,EAAE,aAAa,IAAI,MAAM,O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from '@semiont/core';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
* VectorStore Interface
|
|
5
|
+
*
|
|
6
|
+
* Abstraction over vector database backends (Qdrant, memory).
|
|
7
|
+
* Stores pre-computed embedding vectors with metadata payloads
|
|
8
|
+
* and provides similarity search with payload filtering.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface EmbeddingChunk {
|
|
12
|
+
chunkIndex: number;
|
|
13
|
+
text: string;
|
|
14
|
+
embedding: number[];
|
|
15
|
+
}
|
|
16
|
+
interface AnnotationPayload {
|
|
17
|
+
annotationId: AnnotationId;
|
|
18
|
+
resourceId: ResourceId;
|
|
19
|
+
motivation: string;
|
|
20
|
+
entityTypes: string[];
|
|
21
|
+
exactText: string;
|
|
22
|
+
}
|
|
23
|
+
interface VectorSearchResult {
|
|
24
|
+
id: string;
|
|
25
|
+
score: number;
|
|
26
|
+
resourceId: ResourceId;
|
|
27
|
+
annotationId?: AnnotationId;
|
|
28
|
+
text: string;
|
|
29
|
+
entityTypes?: string[];
|
|
30
|
+
}
|
|
31
|
+
interface SearchOptions {
|
|
32
|
+
limit: number;
|
|
33
|
+
scoreThreshold?: number;
|
|
34
|
+
filter?: {
|
|
35
|
+
entityTypes?: string[];
|
|
36
|
+
resourceId?: ResourceId;
|
|
37
|
+
motivation?: string;
|
|
38
|
+
excludeResourceId?: ResourceId;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
interface VectorStore {
|
|
42
|
+
connect(): Promise<void>;
|
|
43
|
+
disconnect(): Promise<void>;
|
|
44
|
+
isConnected(): boolean;
|
|
45
|
+
clearAll(): Promise<void>;
|
|
46
|
+
upsertResourceVectors(resourceId: ResourceId, chunks: EmbeddingChunk[]): Promise<void>;
|
|
47
|
+
upsertAnnotationVector(annotationId: AnnotationId, embedding: number[], payload: AnnotationPayload): Promise<void>;
|
|
48
|
+
deleteResourceVectors(resourceId: ResourceId): Promise<void>;
|
|
49
|
+
deleteAnnotationVector(annotationId: AnnotationId): Promise<void>;
|
|
50
|
+
searchResources(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
51
|
+
searchAnnotations(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Qdrant VectorStore Implementation
|
|
56
|
+
*
|
|
57
|
+
* Uses the Qdrant REST API via @qdrant/js-client-rest.
|
|
58
|
+
* Manages two collections: 'resources' and 'annotations'.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
interface QdrantConfig {
|
|
62
|
+
host: string;
|
|
63
|
+
port: number;
|
|
64
|
+
dimensions: number;
|
|
65
|
+
}
|
|
66
|
+
declare class QdrantVectorStore implements VectorStore {
|
|
67
|
+
private client;
|
|
68
|
+
private connected;
|
|
69
|
+
private config;
|
|
70
|
+
constructor(config: QdrantConfig);
|
|
71
|
+
connect(): Promise<void>;
|
|
72
|
+
disconnect(): Promise<void>;
|
|
73
|
+
clearAll(): Promise<void>;
|
|
74
|
+
isConnected(): boolean;
|
|
75
|
+
private ensureCollection;
|
|
76
|
+
upsertResourceVectors(resourceId: ResourceId, chunks: EmbeddingChunk[]): Promise<void>;
|
|
77
|
+
upsertAnnotationVector(annotationId: AnnotationId, embedding: number[], payload: AnnotationPayload): Promise<void>;
|
|
78
|
+
deleteResourceVectors(resourceId: ResourceId): Promise<void>;
|
|
79
|
+
deleteAnnotationVector(annotationId: AnnotationId): Promise<void>;
|
|
80
|
+
searchResources(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
81
|
+
searchAnnotations(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
82
|
+
private search;
|
|
83
|
+
private buildFilter;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* In-Memory VectorStore Implementation
|
|
88
|
+
*
|
|
89
|
+
* For testing and development without a running Qdrant instance.
|
|
90
|
+
* Uses brute-force cosine similarity search.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
declare class MemoryVectorStore implements VectorStore {
|
|
94
|
+
private resources;
|
|
95
|
+
private annotations;
|
|
96
|
+
private connected;
|
|
97
|
+
connect(): Promise<void>;
|
|
98
|
+
disconnect(): Promise<void>;
|
|
99
|
+
clearAll(): Promise<void>;
|
|
100
|
+
isConnected(): boolean;
|
|
101
|
+
upsertResourceVectors(resourceId: ResourceId, chunks: EmbeddingChunk[]): Promise<void>;
|
|
102
|
+
upsertAnnotationVector(annotationId: AnnotationId, embedding: number[], payload: AnnotationPayload): Promise<void>;
|
|
103
|
+
deleteResourceVectors(resourceId: ResourceId): Promise<void>;
|
|
104
|
+
deleteAnnotationVector(annotationId: AnnotationId): Promise<void>;
|
|
105
|
+
searchResources(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
106
|
+
searchAnnotations(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
107
|
+
private search;
|
|
108
|
+
private toResult;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* VectorStore Factory
|
|
113
|
+
*
|
|
114
|
+
* Creates a VectorStore instance based on configuration.
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
interface VectorStoreConfig {
|
|
118
|
+
type: 'qdrant' | 'memory';
|
|
119
|
+
host?: string;
|
|
120
|
+
port?: number;
|
|
121
|
+
dimensions: number;
|
|
122
|
+
}
|
|
123
|
+
declare function createVectorStore(config: VectorStoreConfig): Promise<VectorStore>;
|
|
124
|
+
declare function getVectorStore(): VectorStore | null;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* EmbeddingProvider Interface
|
|
128
|
+
*
|
|
129
|
+
* Abstraction over embedding model providers (Voyage AI, Ollama).
|
|
130
|
+
* Converts text into dense vector representations for similarity search.
|
|
131
|
+
*/
|
|
132
|
+
interface EmbeddingProvider {
|
|
133
|
+
/** Embed a single text string. */
|
|
134
|
+
embed(text: string): Promise<number[]>;
|
|
135
|
+
/** Embed multiple texts in a single batch call. */
|
|
136
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
137
|
+
/** The dimensionality of vectors produced by this provider. */
|
|
138
|
+
dimensions(): number;
|
|
139
|
+
/** The model identifier (e.g. "voyage-3", "nomic-embed-text"). */
|
|
140
|
+
model(): string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Voyage AI Embedding Provider
|
|
145
|
+
*
|
|
146
|
+
* Cloud embedding via the Voyage AI API (partner of Anthropic).
|
|
147
|
+
* Uses the same API key as Anthropic inference.
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
interface VoyageConfig {
|
|
151
|
+
apiKey: string;
|
|
152
|
+
model: string;
|
|
153
|
+
endpoint?: string;
|
|
154
|
+
}
|
|
155
|
+
declare class VoyageEmbeddingProvider implements EmbeddingProvider {
|
|
156
|
+
private config;
|
|
157
|
+
constructor(config: VoyageConfig);
|
|
158
|
+
embed(text: string): Promise<number[]>;
|
|
159
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
160
|
+
dimensions(): number;
|
|
161
|
+
model(): string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Ollama Embedding Provider
|
|
166
|
+
*
|
|
167
|
+
* Local embedding via the Ollama API.
|
|
168
|
+
* Uses models like nomic-embed-text, all-minilm, etc.
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
interface OllamaEmbeddingConfig {
|
|
172
|
+
model: string;
|
|
173
|
+
baseURL?: string;
|
|
174
|
+
}
|
|
175
|
+
declare class OllamaEmbeddingProvider implements EmbeddingProvider {
|
|
176
|
+
private config;
|
|
177
|
+
constructor(config: OllamaEmbeddingConfig);
|
|
178
|
+
embed(text: string): Promise<number[]>;
|
|
179
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
180
|
+
dimensions(): number;
|
|
181
|
+
model(): string;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* EmbeddingProvider Factory
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
interface EmbeddingConfig {
|
|
189
|
+
type: 'voyage' | 'ollama';
|
|
190
|
+
model: string;
|
|
191
|
+
apiKey?: string;
|
|
192
|
+
baseURL?: string;
|
|
193
|
+
endpoint?: string;
|
|
194
|
+
}
|
|
195
|
+
declare function createEmbeddingProvider(config: EmbeddingConfig): Promise<EmbeddingProvider>;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Text Chunking Utilities
|
|
199
|
+
*
|
|
200
|
+
* Splits long text into overlapping chunks for embedding.
|
|
201
|
+
* Each chunk is a passage that fits within the embedding model's context window.
|
|
202
|
+
*/
|
|
203
|
+
interface ChunkingConfig {
|
|
204
|
+
chunkSize: number;
|
|
205
|
+
overlap: number;
|
|
206
|
+
}
|
|
207
|
+
declare const DEFAULT_CHUNKING_CONFIG: ChunkingConfig;
|
|
208
|
+
/**
|
|
209
|
+
* Split text into overlapping chunks.
|
|
210
|
+
*
|
|
211
|
+
* Splits on paragraph boundaries when possible, falling back to sentence
|
|
212
|
+
* boundaries, then word boundaries. Each chunk overlaps with the previous
|
|
213
|
+
* by `overlap` tokens worth of text.
|
|
214
|
+
*/
|
|
215
|
+
declare function chunkText(text: string, config?: ChunkingConfig): string[];
|
|
216
|
+
|
|
217
|
+
export { DEFAULT_CHUNKING_CONFIG, MemoryVectorStore, OllamaEmbeddingProvider, QdrantVectorStore, VoyageEmbeddingProvider, chunkText, createEmbeddingProvider, createVectorStore, getVectorStore };
|
|
218
|
+
export type { AnnotationPayload, ChunkingConfig, EmbeddingChunk, EmbeddingConfig, EmbeddingProvider, OllamaEmbeddingConfig, QdrantConfig, SearchOptions, VectorSearchResult, VectorStore, VectorStoreConfig, VoyageConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
QdrantVectorStore
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IWHPVMXW.js";
|
|
4
4
|
import {
|
|
5
5
|
VoyageEmbeddingProvider
|
|
6
6
|
} from "./chunk-INCF7JMV.js";
|
|
@@ -121,7 +121,7 @@ var instance = null;
|
|
|
121
121
|
async function createVectorStore(config) {
|
|
122
122
|
if (instance) return instance;
|
|
123
123
|
if (config.type === "qdrant") {
|
|
124
|
-
const { QdrantVectorStore: QdrantVectorStore2 } = await import("./qdrant-
|
|
124
|
+
const { QdrantVectorStore: QdrantVectorStore2 } = await import("./qdrant-YF2TKFCE.js");
|
|
125
125
|
instance = new QdrantVectorStore2({
|
|
126
126
|
host: config.host ?? "localhost",
|
|
127
127
|
port: config.port ?? 6333,
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semiont/vectors",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=24.0.0"
|
|
6
|
+
},
|
|
4
7
|
"type": "module",
|
|
5
8
|
"description": "Vector storage, embedding, and semantic search for Semiont",
|
|
6
9
|
"main": "dist/index.js",
|
|
@@ -13,19 +16,24 @@
|
|
|
13
16
|
}
|
|
14
17
|
},
|
|
15
18
|
"scripts": {
|
|
16
|
-
"build": "npm run typecheck && tsup && tsc -p tsconfig.build.json",
|
|
19
|
+
"build": "npm run typecheck && tsup && tsc -p tsconfig.build.json && rollup -c rollup.dts.config.mjs && rm -rf dist-types",
|
|
17
20
|
"typecheck": "tsc --noEmit",
|
|
18
|
-
"clean": "rm -rf dist",
|
|
21
|
+
"clean": "rm -rf dist dist-types",
|
|
19
22
|
"test": "vitest run",
|
|
20
|
-
"test:watch": "vitest"
|
|
23
|
+
"test:watch": "vitest",
|
|
24
|
+
"test:coverage": "vitest run --coverage"
|
|
21
25
|
},
|
|
22
26
|
"dependencies": {
|
|
23
|
-
"@qdrant/js-client-rest": "^1.
|
|
27
|
+
"@qdrant/js-client-rest": "^1.18.0",
|
|
24
28
|
"@semiont/core": "*"
|
|
25
29
|
},
|
|
26
30
|
"devDependencies": {
|
|
31
|
+
"@vitest/coverage-v8": "^4.1.8",
|
|
32
|
+
"rollup": "^4.61.0",
|
|
33
|
+
"rollup-plugin-dts": "^6.4.1",
|
|
27
34
|
"tsup": "^8.5.1",
|
|
28
|
-
"typescript": "^6.0.2"
|
|
35
|
+
"typescript": "^6.0.2",
|
|
36
|
+
"vitest": "^4.1.8"
|
|
29
37
|
},
|
|
30
38
|
"files": [
|
|
31
39
|
"dist",
|
package/dist/chunking.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Text Chunking Utilities
|
|
3
|
-
*
|
|
4
|
-
* Splits long text into overlapping chunks for embedding.
|
|
5
|
-
* Each chunk is a passage that fits within the embedding model's context window.
|
|
6
|
-
*/
|
|
7
|
-
export interface ChunkingConfig {
|
|
8
|
-
chunkSize: number;
|
|
9
|
-
overlap: number;
|
|
10
|
-
}
|
|
11
|
-
export declare const DEFAULT_CHUNKING_CONFIG: ChunkingConfig;
|
|
12
|
-
/**
|
|
13
|
-
* Split text into overlapping chunks.
|
|
14
|
-
*
|
|
15
|
-
* Splits on paragraph boundaries when possible, falling back to sentence
|
|
16
|
-
* boundaries, then word boundaries. Each chunk overlaps with the previous
|
|
17
|
-
* by `overlap` tokens worth of text.
|
|
18
|
-
*/
|
|
19
|
-
export declare function chunkText(text: string, config?: ChunkingConfig): string[];
|
|
20
|
-
//# sourceMappingURL=chunking.d.ts.map
|
package/dist/chunking.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chunking.d.ts","sourceRoot":"","sources":["../src/chunking.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,uBAAuB,EAAE,cAGrC,CAAC;AASF;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,cAAwC,GAAG,MAAM,EAAE,CA0ClG"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EmbeddingProvider Factory
|
|
3
|
-
*/
|
|
4
|
-
import type { EmbeddingProvider } from './interface';
|
|
5
|
-
export interface EmbeddingConfig {
|
|
6
|
-
type: 'voyage' | 'ollama';
|
|
7
|
-
model: string;
|
|
8
|
-
apiKey?: string;
|
|
9
|
-
baseURL?: string;
|
|
10
|
-
endpoint?: string;
|
|
11
|
-
}
|
|
12
|
-
export declare function createEmbeddingProvider(config: EmbeddingConfig): Promise<EmbeddingProvider>;
|
|
13
|
-
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/embedding/factory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAoBjG"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EmbeddingProvider Interface
|
|
3
|
-
*
|
|
4
|
-
* Abstraction over embedding model providers (Voyage AI, Ollama).
|
|
5
|
-
* Converts text into dense vector representations for similarity search.
|
|
6
|
-
*/
|
|
7
|
-
export interface EmbeddingProvider {
|
|
8
|
-
/** Embed a single text string. */
|
|
9
|
-
embed(text: string): Promise<number[]>;
|
|
10
|
-
/** Embed multiple texts in a single batch call. */
|
|
11
|
-
embedBatch(texts: string[]): Promise<number[][]>;
|
|
12
|
-
/** The dimensionality of vectors produced by this provider. */
|
|
13
|
-
dimensions(): number;
|
|
14
|
-
/** The model identifier (e.g. "voyage-3", "nomic-embed-text"). */
|
|
15
|
-
model(): string;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/embedding/interface.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,iBAAiB;IAChC,kCAAkC;IAClC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAEvC,mDAAmD;IACnD,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAEjD,+DAA+D;IAC/D,UAAU,IAAI,MAAM,CAAC;IAErB,kEAAkE;IAClE,KAAK,IAAI,MAAM,CAAC;CACjB"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ollama Embedding Provider
|
|
3
|
-
*
|
|
4
|
-
* Local embedding via the Ollama API.
|
|
5
|
-
* Uses models like nomic-embed-text, all-minilm, etc.
|
|
6
|
-
*/
|
|
7
|
-
import type { EmbeddingProvider } from './interface';
|
|
8
|
-
export interface OllamaEmbeddingConfig {
|
|
9
|
-
model: string;
|
|
10
|
-
baseURL?: string;
|
|
11
|
-
}
|
|
12
|
-
export declare class OllamaEmbeddingProvider implements EmbeddingProvider {
|
|
13
|
-
private config;
|
|
14
|
-
constructor(config: OllamaEmbeddingConfig);
|
|
15
|
-
embed(text: string): Promise<number[]>;
|
|
16
|
-
embedBatch(texts: string[]): Promise<number[][]>;
|
|
17
|
-
dimensions(): number;
|
|
18
|
-
model(): string;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=ollama.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ollama.d.ts","sourceRoot":"","sources":["../../src/embedding/ollama.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AASD,qBAAa,uBAAwB,YAAW,iBAAiB;IAC/D,OAAO,CAAC,MAAM,CAAwB;gBAE1B,MAAM,EAAE,qBAAqB;IAInC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAqBtC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IAsBtD,UAAU,IAAI,MAAM;IAIpB,KAAK,IAAI,MAAM;CAGhB"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Voyage AI Embedding Provider
|
|
3
|
-
*
|
|
4
|
-
* Cloud embedding via the Voyage AI API (partner of Anthropic).
|
|
5
|
-
* Uses the same API key as Anthropic inference.
|
|
6
|
-
*/
|
|
7
|
-
import type { EmbeddingProvider } from './interface';
|
|
8
|
-
export interface VoyageConfig {
|
|
9
|
-
apiKey: string;
|
|
10
|
-
model: string;
|
|
11
|
-
endpoint?: string;
|
|
12
|
-
}
|
|
13
|
-
export declare class VoyageEmbeddingProvider implements EmbeddingProvider {
|
|
14
|
-
private config;
|
|
15
|
-
constructor(config: VoyageConfig);
|
|
16
|
-
embed(text: string): Promise<number[]>;
|
|
17
|
-
embedBatch(texts: string[]): Promise<number[][]>;
|
|
18
|
-
dimensions(): number;
|
|
19
|
-
model(): string;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=voyage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"voyage.d.ts","sourceRoot":"","sources":["../../src/embedding/voyage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAUD,qBAAa,uBAAwB,YAAW,iBAAiB;IAC/D,OAAO,CAAC,MAAM,CAAe;gBAEjB,MAAM,EAAE,YAAY;IAI1B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAKtC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IAwBtD,UAAU,IAAI,MAAM;IAIpB,KAAK,IAAI,MAAM;CAGhB"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC3H,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACpE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,YAAY,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAChE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/qdrant-WGOBIU6H.js
DELETED
package/dist/store/factory.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* VectorStore Factory
|
|
3
|
-
*
|
|
4
|
-
* Creates a VectorStore instance based on configuration.
|
|
5
|
-
*/
|
|
6
|
-
import type { VectorStore } from './interface';
|
|
7
|
-
export interface VectorStoreConfig {
|
|
8
|
-
type: 'qdrant' | 'memory';
|
|
9
|
-
host?: string;
|
|
10
|
-
port?: number;
|
|
11
|
-
dimensions: number;
|
|
12
|
-
}
|
|
13
|
-
export declare function createVectorStore(config: VectorStoreConfig): Promise<VectorStore>;
|
|
14
|
-
export declare function getVectorStore(): VectorStore | null;
|
|
15
|
-
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/store/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAID,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAgBvF;AAED,wBAAgB,cAAc,IAAI,WAAW,GAAG,IAAI,CAEnD"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* VectorStore Interface
|
|
3
|
-
*
|
|
4
|
-
* Abstraction over vector database backends (Qdrant, memory).
|
|
5
|
-
* Stores pre-computed embedding vectors with metadata payloads
|
|
6
|
-
* and provides similarity search with payload filtering.
|
|
7
|
-
*/
|
|
8
|
-
import type { ResourceId, AnnotationId } from '@semiont/core';
|
|
9
|
-
export interface EmbeddingChunk {
|
|
10
|
-
chunkIndex: number;
|
|
11
|
-
text: string;
|
|
12
|
-
embedding: number[];
|
|
13
|
-
}
|
|
14
|
-
export interface AnnotationPayload {
|
|
15
|
-
annotationId: AnnotationId;
|
|
16
|
-
resourceId: ResourceId;
|
|
17
|
-
motivation: string;
|
|
18
|
-
entityTypes: string[];
|
|
19
|
-
exactText: string;
|
|
20
|
-
}
|
|
21
|
-
export interface VectorSearchResult {
|
|
22
|
-
id: string;
|
|
23
|
-
score: number;
|
|
24
|
-
resourceId: ResourceId;
|
|
25
|
-
annotationId?: AnnotationId;
|
|
26
|
-
text: string;
|
|
27
|
-
entityTypes?: string[];
|
|
28
|
-
}
|
|
29
|
-
export interface SearchOptions {
|
|
30
|
-
limit: number;
|
|
31
|
-
scoreThreshold?: number;
|
|
32
|
-
filter?: {
|
|
33
|
-
entityTypes?: string[];
|
|
34
|
-
resourceId?: ResourceId;
|
|
35
|
-
motivation?: string;
|
|
36
|
-
excludeResourceId?: ResourceId;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export interface VectorStore {
|
|
40
|
-
connect(): Promise<void>;
|
|
41
|
-
disconnect(): Promise<void>;
|
|
42
|
-
isConnected(): boolean;
|
|
43
|
-
clearAll(): Promise<void>;
|
|
44
|
-
upsertResourceVectors(resourceId: ResourceId, chunks: EmbeddingChunk[]): Promise<void>;
|
|
45
|
-
upsertAnnotationVector(annotationId: AnnotationId, embedding: number[], payload: AnnotationPayload): Promise<void>;
|
|
46
|
-
deleteResourceVectors(resourceId: ResourceId): Promise<void>;
|
|
47
|
-
deleteAnnotationVector(annotationId: AnnotationId): Promise<void>;
|
|
48
|
-
searchResources(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
49
|
-
searchAnnotations(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/store/interface.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE9D,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,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C;CAC5F"}
|
package/dist/store/memory.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* In-Memory VectorStore Implementation
|
|
3
|
-
*
|
|
4
|
-
* For testing and development without a running Qdrant instance.
|
|
5
|
-
* Uses brute-force cosine similarity search.
|
|
6
|
-
*/
|
|
7
|
-
import type { ResourceId, AnnotationId } from '@semiont/core';
|
|
8
|
-
import type { VectorStore, EmbeddingChunk, AnnotationPayload, VectorSearchResult, SearchOptions } from './interface';
|
|
9
|
-
export declare class MemoryVectorStore implements VectorStore {
|
|
10
|
-
private resources;
|
|
11
|
-
private annotations;
|
|
12
|
-
private connected;
|
|
13
|
-
connect(): Promise<void>;
|
|
14
|
-
disconnect(): Promise<void>;
|
|
15
|
-
clearAll(): Promise<void>;
|
|
16
|
-
isConnected(): boolean;
|
|
17
|
-
upsertResourceVectors(resourceId: ResourceId, chunks: EmbeddingChunk[]): Promise<void>;
|
|
18
|
-
upsertAnnotationVector(annotationId: AnnotationId, embedding: number[], payload: AnnotationPayload): Promise<void>;
|
|
19
|
-
deleteResourceVectors(resourceId: ResourceId): Promise<void>;
|
|
20
|
-
deleteAnnotationVector(annotationId: AnnotationId): Promise<void>;
|
|
21
|
-
searchResources(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
22
|
-
searchAnnotations(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
23
|
-
private search;
|
|
24
|
-
private toResult;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/store/memory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AA4BrH,qBAAa,iBAAkB,YAAW,WAAW;IACnD,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,SAAS,CAAS;IAEpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAK/B,WAAW,IAAI,OAAO;IAIhB,qBAAqB,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBtF,sBAAsB,CAC1B,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,MAAM,EAAE,EACnB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC;IAeV,qBAAqB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5D,sBAAsB,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjE,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAIxF,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAIhG,OAAO,CAAC,MAAM;IAmCd,OAAO,CAAC,QAAQ;CAUjB"}
|
package/dist/store/qdrant.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Qdrant VectorStore Implementation
|
|
3
|
-
*
|
|
4
|
-
* Uses the Qdrant REST API via @qdrant/js-client-rest.
|
|
5
|
-
* Manages two collections: 'resources' and 'annotations'.
|
|
6
|
-
*/
|
|
7
|
-
import type { ResourceId, AnnotationId } from '@semiont/core';
|
|
8
|
-
import type { VectorStore, EmbeddingChunk, AnnotationPayload, VectorSearchResult, SearchOptions } from './interface';
|
|
9
|
-
export interface QdrantConfig {
|
|
10
|
-
host: string;
|
|
11
|
-
port: number;
|
|
12
|
-
dimensions: number;
|
|
13
|
-
}
|
|
14
|
-
export declare class QdrantVectorStore implements VectorStore {
|
|
15
|
-
private client;
|
|
16
|
-
private connected;
|
|
17
|
-
private config;
|
|
18
|
-
constructor(config: QdrantConfig);
|
|
19
|
-
connect(): Promise<void>;
|
|
20
|
-
disconnect(): Promise<void>;
|
|
21
|
-
clearAll(): Promise<void>;
|
|
22
|
-
isConnected(): boolean;
|
|
23
|
-
private ensureCollection;
|
|
24
|
-
upsertResourceVectors(resourceId: ResourceId, chunks: EmbeddingChunk[]): Promise<void>;
|
|
25
|
-
upsertAnnotationVector(annotationId: AnnotationId, embedding: number[], payload: AnnotationPayload): Promise<void>;
|
|
26
|
-
deleteResourceVectors(resourceId: ResourceId): Promise<void>;
|
|
27
|
-
deleteAnnotationVector(annotationId: AnnotationId): Promise<void>;
|
|
28
|
-
searchResources(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
29
|
-
searchAnnotations(embedding: number[], opts: SearchOptions): Promise<VectorSearchResult[]>;
|
|
30
|
-
private search;
|
|
31
|
-
private buildFilter;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=qdrant.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"qdrant.d.ts","sourceRoot":"","sources":["../../src/store/qdrant.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAWrH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAA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