@crewhaus/tool-retrieve 0.1.0 → 0.1.2
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/package.json +10 -15
- package/src/index.test.ts +47 -0
- package/src/index.ts +20 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewhaus/tool-retrieve",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Retrieve(query, k?, filter?) tool — composes embedder + vector-store",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
"test": "bun test src"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@crewhaus/embedder": "0.
|
|
16
|
-
"@crewhaus/errors": "0.
|
|
17
|
-
"@crewhaus/tool-builder": "0.
|
|
18
|
-
"@crewhaus/tool-catalog": "0.
|
|
19
|
-
"@crewhaus/vector-store": "0.
|
|
15
|
+
"@crewhaus/embedder": "0.1.2",
|
|
16
|
+
"@crewhaus/errors": "0.1.2",
|
|
17
|
+
"@crewhaus/tool-builder": "0.1.2",
|
|
18
|
+
"@crewhaus/tool-catalog": "0.1.2",
|
|
19
|
+
"@crewhaus/vector-store": "0.1.2",
|
|
20
20
|
"zod": "^3.23.8"
|
|
21
21
|
},
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"author": {
|
|
24
24
|
"name": "Max Meier",
|
|
25
|
-
"email": "max@
|
|
26
|
-
"url": "https://
|
|
25
|
+
"email": "max@crewhaus.ai",
|
|
26
|
+
"url": "https://crewhaus.ai"
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
@@ -35,12 +35,7 @@
|
|
|
35
35
|
"url": "https://github.com/crewhaus/factory/issues"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
|
-
"access": "
|
|
38
|
+
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"files": [
|
|
41
|
-
"src",
|
|
42
|
-
"README.md",
|
|
43
|
-
"LICENSE",
|
|
44
|
-
"NOTICE"
|
|
45
|
-
]
|
|
40
|
+
"files": ["src", "README.md", "LICENSE", "NOTICE"]
|
|
46
41
|
}
|
package/src/index.test.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
2
5
|
import { createEmbedder } from "@crewhaus/embedder";
|
|
3
6
|
import { createVectorStore } from "@crewhaus/vector-store";
|
|
4
7
|
import {
|
|
5
8
|
RetrieveConfigError,
|
|
6
9
|
_resetRetrieveConfig,
|
|
10
|
+
getRetrieveConfig,
|
|
7
11
|
registerRetrieveConfig,
|
|
8
12
|
retrieve,
|
|
9
13
|
} from "./index";
|
|
@@ -101,4 +105,47 @@ describe("registerRetrieveConfig variants", () => {
|
|
|
101
105
|
});
|
|
102
106
|
// No throw — config built lazily.
|
|
103
107
|
});
|
|
108
|
+
|
|
109
|
+
test("constructs a lance store from vectorBackend + url (on-disk index path)", () => {
|
|
110
|
+
// Pass an explicit temp path so the test never writes the default
|
|
111
|
+
// `.crewhaus/vectors/lance` dir into the working tree.
|
|
112
|
+
const dir = mkdtempSync(join(tmpdir(), "crewhaus-retrieve-lance-"));
|
|
113
|
+
try {
|
|
114
|
+
registerRetrieveConfig({ embedderModel: "mock/det", vectorBackend: "lance", url: dir });
|
|
115
|
+
expect(getRetrieveConfig()?.vectorStore.backend).toBe("lance");
|
|
116
|
+
} finally {
|
|
117
|
+
rmSync(dir, { recursive: true, force: true });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("constructs an http (qdrant) store from vectorBackend + url + collection + apiKey", () => {
|
|
122
|
+
registerRetrieveConfig({
|
|
123
|
+
embedderModel: "mock/det",
|
|
124
|
+
vectorBackend: "qdrant",
|
|
125
|
+
url: "https://qdrant.example",
|
|
126
|
+
collection: "docs",
|
|
127
|
+
apiKey: "test-key",
|
|
128
|
+
});
|
|
129
|
+
expect(getRetrieveConfig()?.vectorStore.backend).toBe("qdrant");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("an http backend missing url throws (config reaches the factory guard)", () => {
|
|
133
|
+
expect(() =>
|
|
134
|
+
registerRetrieveConfig({
|
|
135
|
+
embedderModel: "mock/det",
|
|
136
|
+
vectorBackend: "qdrant",
|
|
137
|
+
collection: "docs",
|
|
138
|
+
}),
|
|
139
|
+
).toThrow(/requires url/);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("an http backend missing collection throws", () => {
|
|
143
|
+
expect(() =>
|
|
144
|
+
registerRetrieveConfig({
|
|
145
|
+
embedderModel: "mock/det",
|
|
146
|
+
vectorBackend: "weaviate",
|
|
147
|
+
url: "https://weaviate.example",
|
|
148
|
+
}),
|
|
149
|
+
).toThrow(/requires collection/);
|
|
150
|
+
});
|
|
104
151
|
});
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { type Embedder, createEmbedder } from "@crewhaus/embedder";
|
|
|
18
18
|
import { CrewhausError } from "@crewhaus/errors";
|
|
19
19
|
import { buildTool } from "@crewhaus/tool-builder";
|
|
20
20
|
import type { RegisteredTool } from "@crewhaus/tool-catalog";
|
|
21
|
-
import { type VectorStore, createVectorStore } from "@crewhaus/vector-store";
|
|
21
|
+
import { type VectorBackendId, type VectorStore, createVectorStore } from "@crewhaus/vector-store";
|
|
22
22
|
import { z } from "zod";
|
|
23
23
|
|
|
24
24
|
export class RetrieveConfigError extends CrewhausError {
|
|
@@ -39,7 +39,19 @@ export type RetrieveConfigInput = {
|
|
|
39
39
|
readonly embedderModel?: string;
|
|
40
40
|
readonly embedderApiKey?: string;
|
|
41
41
|
readonly vectorStore?: VectorStore;
|
|
42
|
-
readonly vectorBackend?:
|
|
42
|
+
readonly vectorBackend?: VectorBackendId;
|
|
43
|
+
/**
|
|
44
|
+
* Connection config for the chosen `vectorBackend`, consulted only when no
|
|
45
|
+
* `vectorStore` instance is supplied. Mirrors the pipeline spec's
|
|
46
|
+
* `retrieve.{url,collection,apiKey}`. The HTTP backends
|
|
47
|
+
* (qdrant/pinecone/weaviate) require `url` + `collection`; lance reads
|
|
48
|
+
* `url` as its on-disk index path. `apiKey` here is the vector store's,
|
|
49
|
+
* distinct from `embedderApiKey`. (At runtime the caller passes the
|
|
50
|
+
* resolved secret — there is no bundle to keep it out of.)
|
|
51
|
+
*/
|
|
52
|
+
readonly url?: string;
|
|
53
|
+
readonly collection?: string;
|
|
54
|
+
readonly apiKey?: string;
|
|
43
55
|
readonly defaultK?: number;
|
|
44
56
|
readonly default_k?: number;
|
|
45
57
|
};
|
|
@@ -56,7 +68,12 @@ export function registerRetrieveConfig(input: RetrieveConfigInput): void {
|
|
|
56
68
|
}
|
|
57
69
|
let vectorStore = input.vectorStore;
|
|
58
70
|
if (vectorStore === undefined) {
|
|
59
|
-
vectorStore = createVectorStore({
|
|
71
|
+
vectorStore = createVectorStore({
|
|
72
|
+
backend: input.vectorBackend ?? "in-memory",
|
|
73
|
+
...(input.url !== undefined ? { url: input.url } : {}),
|
|
74
|
+
...(input.apiKey !== undefined ? { apiKey: input.apiKey } : {}),
|
|
75
|
+
...(input.collection !== undefined ? { collection: input.collection } : {}),
|
|
76
|
+
});
|
|
60
77
|
}
|
|
61
78
|
if (embedder === undefined) {
|
|
62
79
|
throw new RetrieveConfigError(
|