@semiont/vectors 0.5.5 → 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.js +2 -2
- package/dist/qdrant-YF2TKFCE.js +7 -0
- package/package.json +11 -5
- package/dist/qdrant-WGOBIU6H.js +0 -7
- /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,OAAO,wBAAwB;AAC9D,SAAK,SAAS,IAAI,aAAa;AAAA,MAC7B,MAAM,KAAK,OAAO;AAAA,MAClB,MAAM,KAAK,OAAO;AAAA,IACpB,CAAC;AAGD,UAAM,KAAK,iBAAiB,aAAa,KAAK,OAAO,UAAU;AAC/D,UAAM,KAAK,iBAAiB,eAAe,KAAK,OAAO,UAAU;AACjE,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAM,aAA4B;AAChC,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAM,WAA0B;AAC9B,QAAI;AAAE,YAAM,KAAK,OAAO,iBAAiB,WAAW;AAAA,IAAG,QAAQ;AAAA,IAAsB;AACrF,QAAI;AAAE,YAAM,KAAK,OAAO,iBAAiB,aAAa;AAAA,IAAG,QAAQ;AAAA,IAAsB;AACvF,UAAM,KAAK,iBAAiB,a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AAY;AACrB,WAAK,KAAK,EAAE,KAAK,cAAc,OAAO,EAAE,OAAO,OAAO,OAAO,UAAU,EAAE,EAAE,CAAC;AAAA,IAC9E;AAEA,QAAI,OAAO,YAAY;AACrB,WAAK,KAAK,EAAE,KAAK,cAAc,OAAO,EAAE,OAAO,OAAO,WAAW,EAAE,CAAC;AAAA,IACtE;AAEA,UAAM,WAAkB,CAAC;AAEzB,QAAI,OAAO,mBAAmB;AAC5B,eAAS,KAAK,EAAE,KAAK,cAAc,OAAO,EAAE,OAAO,OAAO,OAAO,iBAAiB,EAAE,EAAE,CAAC;AAAA,IACzF;AAEA,QAAI,KAAK,WAAW,KAAK,SAAS,WAAW,EAAG,QAAO;AAEvD,WAAO;AAAA,MACL,GAAI,KAAK,SAAS,IAAI,EAAE,KAAK,IAAI,CAAC;AAAA,MAClC,GAAI,SAAS,SAAS,IAAI,EAAE,SAAS,IAAI,CAAC;AAAA,IAC5C;AAAA,EACF;AACF;","names":[]}
|
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",
|
|
@@ -17,17 +20,20 @@
|
|
|
17
20
|
"typecheck": "tsc --noEmit",
|
|
18
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": {
|
|
27
|
-
"
|
|
31
|
+
"@vitest/coverage-v8": "^4.1.8",
|
|
32
|
+
"rollup": "^4.61.0",
|
|
28
33
|
"rollup-plugin-dts": "^6.4.1",
|
|
29
34
|
"tsup": "^8.5.1",
|
|
30
|
-
"typescript": "^6.0.2"
|
|
35
|
+
"typescript": "^6.0.2",
|
|
36
|
+
"vitest": "^4.1.8"
|
|
31
37
|
},
|
|
32
38
|
"files": [
|
|
33
39
|
"dist",
|
package/dist/qdrant-WGOBIU6H.js
DELETED
|
File without changes
|