@lmnr-ai/lmnr 0.4.21 → 0.4.23
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/README.md +16 -0
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +56 -13
- package/dist/index.d.ts +56 -13
- package/dist/index.js +86 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/decorators.ts +3 -1
- package/src/laminar.ts +103 -23
- package/src/types.ts +11 -0
package/README.md
CHANGED
|
@@ -172,3 +172,19 @@ Resulting in:
|
|
|
172
172
|
runId: '05383a95-d316-4091-a64b-06c54d12982a'
|
|
173
173
|
}
|
|
174
174
|
```
|
|
175
|
+
|
|
176
|
+
## Semantic search
|
|
177
|
+
|
|
178
|
+
You can perform a semantic search on a dataset using the `semanticSearch` method.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { Laminar } from '@lmnr-ai/lmnr';
|
|
182
|
+
|
|
183
|
+
const l = new Laminar('<YOUR_PROJECT_API_KEY>');
|
|
184
|
+
const result = await l.semanticSearch({
|
|
185
|
+
query: 'hello',
|
|
186
|
+
datasetId: 'my_dataset_id',
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
[Read docs](https://docs.lmnr.ai/datasets/indexing#searching) to learn more about semantic search.
|
package/dist/cli.js
CHANGED
|
@@ -36,7 +36,7 @@ var require_package = __commonJS({
|
|
|
36
36
|
"package.json"(exports2, module2) {
|
|
37
37
|
module2.exports = {
|
|
38
38
|
name: "@lmnr-ai/lmnr",
|
|
39
|
-
version: "0.4.
|
|
39
|
+
version: "0.4.23",
|
|
40
40
|
description: "TypeScript SDK for Laminar AI",
|
|
41
41
|
main: "dist/index.js",
|
|
42
42
|
types: "dist/index.d.ts",
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@lmnr-ai/lmnr\",\n \"version\": \"0.4.
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@lmnr-ai/lmnr\",\n \"version\": \"0.4.23\",\n \"description\": \"TypeScript SDK for Laminar AI\",\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"scripts\": {\n \"build\": \"tsup src/index.ts src/cli.ts --format esm,cjs --dts\",\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n },\n \"bin\": {\n \"lmnr\": \"./dist/cli.js\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/lmnr-ai/lmnr-ts.git\"\n },\n \"keywords\": [\n \"laminar\",\n \"lmnr\",\n \"sdk\",\n \"lmnr.ai\"\n ],\n \"author\": \"founders@lmnr.ai\",\n \"license\": \"Apache-2.0\",\n \"bugs\": {\n \"url\": \"https://github.com/lmnr-ai/lmnr-ts/issues\"\n },\n \"homepage\": \"https://github.com/lmnr-ai/lmnr-ts#README\",\n \"devDependencies\": {\n \"@anthropic-ai/sdk\": \"^0.27.3\",\n \"@aws-sdk/client-bedrock-runtime\": \"^3.679.0\",\n \"@azure/openai\": \"1.0.0-beta.13\",\n \"@google-cloud/aiplatform\": \"^3.29.0\",\n \"@google-cloud/vertexai\": \"^1.7.0\",\n \"@langchain/core\": \"^0.3.2\",\n \"@pinecone-database/pinecone\": \"^3.0.3\",\n \"@qdrant/js-client-rest\": \"^1.11.0\",\n \"@types/argparse\": \"^2.0.16\",\n \"@types/cli-progress\": \"^3.11.6\",\n \"@types/node\": \"^22.5.5\",\n \"@types/semver\": \"^7.5.8\",\n \"@types/uuid\": \"^10.0.0\",\n \"bufferutil\": \"^4.0.8\",\n \"chromadb\": \"^1.9.2\",\n \"cohere-ai\": \"^7.14.0\",\n \"langchain\": \"^0.3.2\",\n \"llamaindex\": \"^0.7.10\",\n \"openai\": \"^4.62.1\",\n \"runnables\": \"link:@langchain/core/runnables\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^5.6.2\",\n \"vectorstores\": \"link:@langchain/core/vectorstores\"\n },\n \"dependencies\": {\n \"@grpc/grpc-js\": \"^1.11.3\",\n \"@opentelemetry/api\": \"^1.9.0\",\n \"@opentelemetry/core\": \"^1.26.0\",\n \"@opentelemetry/exporter-trace-otlp-grpc\": \"^0.53.0\",\n \"@opentelemetry/exporter-trace-otlp-proto\": \"^0.53.0\",\n \"@opentelemetry/instrumentation\": \"^0.53.0\",\n \"@opentelemetry/sdk-node\": \"^0.53.0\",\n \"@opentelemetry/sdk-trace-base\": \"^1.26.0\",\n \"@opentelemetry/sdk-trace-node\": \"^1.26.0\",\n \"@opentelemetry/semantic-conventions\": \"^1.27.0\",\n \"@traceloop/ai-semantic-conventions\": \"^0.11.0\",\n \"@traceloop/instrumentation-anthropic\": \"^0.11.1\",\n \"@traceloop/instrumentation-azure\": \"^0.11.1\",\n \"@traceloop/instrumentation-bedrock\": \"^0.11.1\",\n \"@traceloop/instrumentation-chromadb\": \"^0.11.3\",\n \"@traceloop/instrumentation-cohere\": \"^0.11.1\",\n \"@traceloop/instrumentation-langchain\": \"^0.11.1\",\n \"@traceloop/instrumentation-llamaindex\": \"^0.11.1\",\n \"@traceloop/instrumentation-openai\": \"^0.11.3\",\n \"@traceloop/instrumentation-pinecone\": \"^0.11.1\",\n \"@traceloop/instrumentation-qdrant\": \"^0.11.1\",\n \"@traceloop/instrumentation-vertexai\": \"^0.11.1\",\n \"argparse\": \">=2.0\",\n \"cli-progress\": \">=3.12\",\n \"esbuild\": \">=0.23\",\n \"uuid\": \">=10.0.0\"\n }\n}\n","#!/usr/bin/env node\n\nimport { ArgumentParser } from \"argparse\";\nimport * as esbuild from \"esbuild\";\n\nconst pjson = require('../package.json');\n\nexport function loadModule({\n filename,\n moduleText,\n}: {\n filename: string;\n moduleText: string;\n}) {\n // TODO: Figure out how to remove all ts-ignores\n // TODO: Cleanup by setting the original values of _evaluation and _set_global_evaluation back\n // @ts-ignore\n globalThis._evaluation = undefined; // @ts-ignore\n globalThis._set_global_evaluation = true; // @ts-ignore\n\n // it needs \"require\" to be passed in\n new Function(\"require\", moduleText)(require);\n\n // Return the modified _evals global variable\n // @ts-ignore\n return globalThis._evaluation;\n}\n\nasync function cli() {\n const [, , ...args] = process.argv;\n\n // Use argparse, which is the port of the python library\n const parser = new ArgumentParser({\n prog: \"lmnr\",\n description: \"CLI for Laminar\",\n });\n\n parser.add_argument(\"-v\", \"--version\", { action: \"version\", version: pjson.version });\n\n const subparsers = parser.add_subparsers({\n title: \"subcommands\",\n dest: \"subcommand\",\n });\n\n const parser_eval = subparsers.add_parser(\"eval\", {\n description: \"Run an evaluation\",\n });\n\n parser_eval.add_argument(\"file\", {\n help: \"A file containing the evaluation to run\",\n });\n\n parser_eval.set_defaults({\n func: async (args: any) => {\n // TODO: Add various optimizations, e.g. minify, pure, tree shaking, etc.\n const buildOptions = {\n entryPoints: [args.file],\n outfile: \"tmp_out.js\",\n write: false, // will be loaded in memory as a temp file\n platform: \"node\" as esbuild.Platform,\n bundle: true,\n external: [\"node_modules/*\"],\n };\n\n const result = await esbuild.build(buildOptions);\n\n if (!result.outputFiles) {\n console.error(\"Error when building: No output files found\");\n process.exit(1);\n }\n\n const outputFileText = result.outputFiles[0].text;\n\n const evaluation = loadModule({\n filename: args.file,\n moduleText: outputFileText,\n });\n\n // @ts-ignore\n await evaluation.run();\n }\n });\n\n const parsed = parser.parse_args(args);\n await parsed.func(parsed);\n}\n\ncli();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,iBAAAA,UAAAC,SAAA;AAAA,IAAAA,QAAA;AAAA,MACE,MAAQ;AAAA,MACR,SAAW;AAAA,MACX,aAAe;AAAA,MACf,MAAQ;AAAA,MACR,OAAS;AAAA,M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AAE;AAE7C,YAAM,aAAa,WAAW;AAAA,QAC5B,UAAUA,MAAK;AAAA,QACf,YAAY;AAAA,MACd,CAAC;AAGD,YAAM,WAAW,IAAI;AAAA,IACvB;AAAA,EACF,CAAC;AAED,QAAM,SAAS,OAAO,WAAW,IAAI;AACrC,QAAM,OAAO,KAAK,MAAM;AAC1B;AAEA,IAAI;","names":["exports","module","args"]}
|
package/dist/cli.mjs
CHANGED
|
@@ -15,7 +15,7 @@ var require_package = __commonJS({
|
|
|
15
15
|
"package.json"(exports, module) {
|
|
16
16
|
module.exports = {
|
|
17
17
|
name: "@lmnr-ai/lmnr",
|
|
18
|
-
version: "0.4.
|
|
18
|
+
version: "0.4.23",
|
|
19
19
|
description: "TypeScript SDK for Laminar AI",
|
|
20
20
|
main: "dist/index.js",
|
|
21
21
|
types: "dist/index.d.ts",
|
package/dist/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@lmnr-ai/lmnr\",\n \"version\": \"0.4.
|
|
1
|
+
{"version":3,"sources":["../package.json","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@lmnr-ai/lmnr\",\n \"version\": \"0.4.23\",\n \"description\": \"TypeScript SDK for Laminar AI\",\n \"main\": \"dist/index.js\",\n \"types\": \"dist/index.d.ts\",\n \"scripts\": {\n \"build\": \"tsup src/index.ts src/cli.ts --format esm,cjs --dts\",\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n },\n \"bin\": {\n \"lmnr\": \"./dist/cli.js\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/lmnr-ai/lmnr-ts.git\"\n },\n \"keywords\": [\n \"laminar\",\n \"lmnr\",\n \"sdk\",\n \"lmnr.ai\"\n ],\n \"author\": \"founders@lmnr.ai\",\n \"license\": \"Apache-2.0\",\n \"bugs\": {\n \"url\": \"https://github.com/lmnr-ai/lmnr-ts/issues\"\n },\n \"homepage\": \"https://github.com/lmnr-ai/lmnr-ts#README\",\n \"devDependencies\": {\n \"@anthropic-ai/sdk\": \"^0.27.3\",\n \"@aws-sdk/client-bedrock-runtime\": \"^3.679.0\",\n \"@azure/openai\": \"1.0.0-beta.13\",\n \"@google-cloud/aiplatform\": \"^3.29.0\",\n \"@google-cloud/vertexai\": \"^1.7.0\",\n \"@langchain/core\": \"^0.3.2\",\n \"@pinecone-database/pinecone\": \"^3.0.3\",\n \"@qdrant/js-client-rest\": \"^1.11.0\",\n \"@types/argparse\": \"^2.0.16\",\n \"@types/cli-progress\": \"^3.11.6\",\n \"@types/node\": \"^22.5.5\",\n \"@types/semver\": \"^7.5.8\",\n \"@types/uuid\": \"^10.0.0\",\n \"bufferutil\": \"^4.0.8\",\n \"chromadb\": \"^1.9.2\",\n \"cohere-ai\": \"^7.14.0\",\n \"langchain\": \"^0.3.2\",\n \"llamaindex\": \"^0.7.10\",\n \"openai\": \"^4.62.1\",\n \"runnables\": \"link:@langchain/core/runnables\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^5.6.2\",\n \"vectorstores\": \"link:@langchain/core/vectorstores\"\n },\n \"dependencies\": {\n \"@grpc/grpc-js\": \"^1.11.3\",\n \"@opentelemetry/api\": \"^1.9.0\",\n \"@opentelemetry/core\": \"^1.26.0\",\n \"@opentelemetry/exporter-trace-otlp-grpc\": \"^0.53.0\",\n \"@opentelemetry/exporter-trace-otlp-proto\": \"^0.53.0\",\n \"@opentelemetry/instrumentation\": \"^0.53.0\",\n \"@opentelemetry/sdk-node\": \"^0.53.0\",\n \"@opentelemetry/sdk-trace-base\": \"^1.26.0\",\n \"@opentelemetry/sdk-trace-node\": \"^1.26.0\",\n \"@opentelemetry/semantic-conventions\": \"^1.27.0\",\n \"@traceloop/ai-semantic-conventions\": \"^0.11.0\",\n \"@traceloop/instrumentation-anthropic\": \"^0.11.1\",\n \"@traceloop/instrumentation-azure\": \"^0.11.1\",\n \"@traceloop/instrumentation-bedrock\": \"^0.11.1\",\n \"@traceloop/instrumentation-chromadb\": \"^0.11.3\",\n \"@traceloop/instrumentation-cohere\": \"^0.11.1\",\n \"@traceloop/instrumentation-langchain\": \"^0.11.1\",\n \"@traceloop/instrumentation-llamaindex\": \"^0.11.1\",\n \"@traceloop/instrumentation-openai\": \"^0.11.3\",\n \"@traceloop/instrumentation-pinecone\": \"^0.11.1\",\n \"@traceloop/instrumentation-qdrant\": \"^0.11.1\",\n \"@traceloop/instrumentation-vertexai\": \"^0.11.1\",\n \"argparse\": \">=2.0\",\n \"cli-progress\": \">=3.12\",\n \"esbuild\": \">=0.23\",\n \"uuid\": \">=10.0.0\"\n }\n}\n","#!/usr/bin/env node\n\nimport { ArgumentParser } from \"argparse\";\nimport * as esbuild from \"esbuild\";\n\nconst pjson = require('../package.json');\n\nexport function loadModule({\n filename,\n moduleText,\n}: {\n filename: string;\n moduleText: string;\n}) {\n // TODO: Figure out how to remove all ts-ignores\n // TODO: Cleanup by setting the original values of _evaluation and _set_global_evaluation back\n // @ts-ignore\n globalThis._evaluation = undefined; // @ts-ignore\n globalThis._set_global_evaluation = true; // @ts-ignore\n\n // it needs \"require\" to be passed in\n new Function(\"require\", moduleText)(require);\n\n // Return the modified _evals global variable\n // @ts-ignore\n return globalThis._evaluation;\n}\n\nasync function cli() {\n const [, , ...args] = process.argv;\n\n // Use argparse, which is the port of the python library\n const parser = new ArgumentParser({\n prog: \"lmnr\",\n description: \"CLI for Laminar\",\n });\n\n parser.add_argument(\"-v\", \"--version\", { action: \"version\", version: pjson.version });\n\n const subparsers = parser.add_subparsers({\n title: \"subcommands\",\n dest: \"subcommand\",\n });\n\n const parser_eval = subparsers.add_parser(\"eval\", {\n description: \"Run an evaluation\",\n });\n\n parser_eval.add_argument(\"file\", {\n help: \"A file containing the evaluation to run\",\n });\n\n parser_eval.set_defaults({\n func: async (args: any) => {\n // TODO: Add various optimizations, e.g. minify, pure, tree shaking, etc.\n const buildOptions = {\n entryPoints: [args.file],\n outfile: \"tmp_out.js\",\n write: false, // will be loaded in memory as a temp file\n platform: \"node\" as esbuild.Platform,\n bundle: true,\n external: [\"node_modules/*\"],\n };\n\n const result = await esbuild.build(buildOptions);\n\n if (!result.outputFiles) {\n console.error(\"Error when building: No output files found\");\n process.exit(1);\n }\n\n const outputFileText = result.outputFiles[0].text;\n\n const evaluation = loadModule({\n filename: args.file,\n moduleText: outputFileText,\n });\n\n // @ts-ignore\n await evaluation.run();\n }\n });\n\n const parsed = parser.parse_args(args);\n await parsed.func(parsed);\n}\n\ncli();\n"],"mappings":";;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,MACE,MAAQ;AAAA,MACR,SAAW;AAAA,MACX,aAAe;AAAA,MACf,MAAQ;AAAA,MACR,OAAS;AAAA,MACT,SAAW;AAAA,QACT,OAAS;AAAA,QACT,MAAQ;AAAA,MACV;AAAA,MACA,KAAO;AAAA,QACL,MAAQ;AAAA,MACV;AAAA,MACA,YAAc;AAAA,QACZ,MAAQ;AAAA,QACR,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,QAAU;AAAA,MACV,SAAW;AAAA,MACX,MAAQ;AAAA,QACN,KAAO;AAAA,MACT;AAAA,MACA,UAAY;AAAA,MACZ,iBAAmB;AAAA,QACjB,qBAAqB;AAAA,QACrB,mCAAmC;AAAA,QACnC,iBAAiB;AAAA,QACjB,4BAA4B;AAAA,QAC5B,0BAA0B;AAAA,QAC1B,mBAAmB;AAAA,QACnB,+BAA+B;AAAA,QAC/B,0BAA0B;AAAA,QAC1B,mBAAmB;AAAA,QACnB,uBAAuB;AAAA,QACvB,eAAe;AAAA,QACf,iBAAiB;AAAA,QACjB,eAAe;AAAA,QACf,YAAc;AAAA,QACd,UAAY;AAAA,QACZ,aAAa;AAAA,QACb,WAAa;AAAA,QACb,YAAc;AAAA,QACd,QAAU;AAAA,QACV,WAAa;AAAA,QACb,MAAQ;A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,cAAY,aAAa,QAAQ;AAAA,IAC/B,MAAM;AAAA,EACR,CAAC;AAED,cAAY,aAAa;AAAA,IACvB,MAAM,OAAOA,UAAc;AAEzB,YAAM,eAAe;AAAA,QACnB,aAAa,CAACA,MAAK,IAAI;AAAA,QACvB,SAAS;AAAA,QACT,OAAO;AAAA;AAAA,QACP,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,UAAU,CAAC,gBAAgB;AAAA,MAC7B;AAEA,YAAM,SAAS,MAAc,cAAM,YAAY;AAE/C,UAAI,CAAC,OAAO,aAAa;AACvB,gBAAQ,MAAM,4CAA4C;AAC1D,gBAAQ,KAAK,CAAC;AAAA,MAChB;AAEA,YAAM,iBAAiB,OAAO,YAAY,CAAC,EAAE;AAE7C,YAAM,aAAa,WAAW;AAAA,QAC5B,UAAUA,MAAK;AAAA,QACf,YAAY;AAAA,MACd,CAAC;AAGD,YAAM,WAAW,IAAI;AAAA,IACvB;AAAA,EACF,CAAC;AAED,QAAM,SAAS,OAAO,WAAW,IAAI;AACrC,QAAM,OAAO,KAAK,MAAM;AAC1B;AAEA,IAAI;","names":["args"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -318,6 +318,15 @@ type GetDatapointsResponse<D, T> = {
|
|
|
318
318
|
totalCount: number;
|
|
319
319
|
anyInProject: boolean;
|
|
320
320
|
};
|
|
321
|
+
type SemanticSearchResult = {
|
|
322
|
+
datasetId: StringUUID;
|
|
323
|
+
data: Record<string, any>;
|
|
324
|
+
content: string;
|
|
325
|
+
score: number;
|
|
326
|
+
};
|
|
327
|
+
type SemanticSearchResponse = {
|
|
328
|
+
results: SemanticSearchResult[];
|
|
329
|
+
};
|
|
321
330
|
/**
|
|
322
331
|
* Trace types to categorize traces.
|
|
323
332
|
* They are used as association properties passed to all spans in a trace.
|
|
@@ -425,6 +434,21 @@ declare class Laminar {
|
|
|
425
434
|
* key or if the request fails.
|
|
426
435
|
*/
|
|
427
436
|
static run({ pipeline, inputs, env, metadata, currentSpanId, currentTraceId, }: PipelineRunRequest): Promise<PipelineRunResponse>;
|
|
437
|
+
/**
|
|
438
|
+
* Perform a semantic search on a dataset.
|
|
439
|
+
*
|
|
440
|
+
* @param query - The query string to search with.
|
|
441
|
+
* @param datasetId - The ID of the dataset to search in.
|
|
442
|
+
* @param limit - The maximum number of results to return.
|
|
443
|
+
* @param threshold - The minimum score for the results to be returned.
|
|
444
|
+
* @returns Response object containing the search results in descending order of relevance.
|
|
445
|
+
*/
|
|
446
|
+
static semanticSearch({ query, datasetId, limit, threshold, }: {
|
|
447
|
+
query: string;
|
|
448
|
+
datasetId: string;
|
|
449
|
+
limit?: number;
|
|
450
|
+
threshold?: number;
|
|
451
|
+
}): Promise<SemanticSearchResponse>;
|
|
428
452
|
/**
|
|
429
453
|
* Associates an event with the current span. If event with such name never
|
|
430
454
|
* existed, Laminar will create a new event and infer its type from the value.
|
|
@@ -443,24 +467,42 @@ declare class Laminar {
|
|
|
443
467
|
static event(name: string, value?: AttributeValue, timestamp?: TimeInput): void;
|
|
444
468
|
/**
|
|
445
469
|
* Sets the session information for the current span and returns the
|
|
446
|
-
* context to use for the following spans.
|
|
470
|
+
* context to use for the following spans. Returns the result of the
|
|
471
|
+
* function execution, so can be used in an `await` statement.
|
|
447
472
|
*
|
|
448
473
|
* @param sessionId - The session ID to associate with the context.
|
|
449
|
-
* @param
|
|
450
|
-
* @returns The
|
|
474
|
+
* @param fn - Function to execute within the session context.
|
|
475
|
+
* @returns The result of the function execution.
|
|
451
476
|
*
|
|
452
477
|
* @example
|
|
453
|
-
* import {
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
* contextApi.with(context, () => {
|
|
457
|
-
* // Your code here
|
|
478
|
+
* import { Laminar, observe } from '@lmnr-ai/lmnr';
|
|
479
|
+
* const result = await Laminar.withSession("session1234", async () => {
|
|
480
|
+
* // Your code here
|
|
458
481
|
* });
|
|
459
482
|
*/
|
|
460
|
-
static
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
483
|
+
static withSession<T>(sessionId: string, fn: () => T): T;
|
|
484
|
+
/**
|
|
485
|
+
* Sets the metadata for the current span and returns the context to use for
|
|
486
|
+
* the following spans. Returns the result of the function execution, so can
|
|
487
|
+
* be used in an `await` statement.
|
|
488
|
+
*
|
|
489
|
+
* @param metadata - The metadata to associate with the context. Set of string key
|
|
490
|
+
* string value pairs.
|
|
491
|
+
* @param fn - Function to execute within the metadata context.
|
|
492
|
+
* @returns The result of the function execution.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* import { Laminar } from '@lmnr-ai/lmnr';
|
|
496
|
+
* const result = await Laminar.withMetadata(
|
|
497
|
+
* {
|
|
498
|
+
* "my_metadata_key": "my_metadata_value"
|
|
499
|
+
* },
|
|
500
|
+
* async () => {
|
|
501
|
+
* // Your code here
|
|
502
|
+
* }
|
|
503
|
+
* );
|
|
504
|
+
*/
|
|
505
|
+
static withMetadata<T>(metadata: Record<string, string>, fn: () => T): T;
|
|
464
506
|
/**
|
|
465
507
|
* Set attributes for the current span. Useful for manual
|
|
466
508
|
* instrumentation.
|
|
@@ -576,7 +618,8 @@ interface ObserveOptions {
|
|
|
576
618
|
* functions and methods to create spans.
|
|
577
619
|
*
|
|
578
620
|
* @param name - Name of the span. Function name is used if not specified.
|
|
579
|
-
* @param userId -
|
|
621
|
+
* @param userId - Deprecated. Use {@link Laminar.withMetadata} to set key-value pairs.
|
|
622
|
+
* User ID to associate with the span and the following context.
|
|
580
623
|
* @param sessionId - Session ID to associate with the span and the following context.
|
|
581
624
|
* @param traceType – Type of the trace. Unless it is within evaluation, it should be 'DEFAULT'.
|
|
582
625
|
* @param spanType - Type of the span. 'DEFAULT' is used if not specified. If the type is 'LLM',
|
package/dist/index.d.ts
CHANGED
|
@@ -318,6 +318,15 @@ type GetDatapointsResponse<D, T> = {
|
|
|
318
318
|
totalCount: number;
|
|
319
319
|
anyInProject: boolean;
|
|
320
320
|
};
|
|
321
|
+
type SemanticSearchResult = {
|
|
322
|
+
datasetId: StringUUID;
|
|
323
|
+
data: Record<string, any>;
|
|
324
|
+
content: string;
|
|
325
|
+
score: number;
|
|
326
|
+
};
|
|
327
|
+
type SemanticSearchResponse = {
|
|
328
|
+
results: SemanticSearchResult[];
|
|
329
|
+
};
|
|
321
330
|
/**
|
|
322
331
|
* Trace types to categorize traces.
|
|
323
332
|
* They are used as association properties passed to all spans in a trace.
|
|
@@ -425,6 +434,21 @@ declare class Laminar {
|
|
|
425
434
|
* key or if the request fails.
|
|
426
435
|
*/
|
|
427
436
|
static run({ pipeline, inputs, env, metadata, currentSpanId, currentTraceId, }: PipelineRunRequest): Promise<PipelineRunResponse>;
|
|
437
|
+
/**
|
|
438
|
+
* Perform a semantic search on a dataset.
|
|
439
|
+
*
|
|
440
|
+
* @param query - The query string to search with.
|
|
441
|
+
* @param datasetId - The ID of the dataset to search in.
|
|
442
|
+
* @param limit - The maximum number of results to return.
|
|
443
|
+
* @param threshold - The minimum score for the results to be returned.
|
|
444
|
+
* @returns Response object containing the search results in descending order of relevance.
|
|
445
|
+
*/
|
|
446
|
+
static semanticSearch({ query, datasetId, limit, threshold, }: {
|
|
447
|
+
query: string;
|
|
448
|
+
datasetId: string;
|
|
449
|
+
limit?: number;
|
|
450
|
+
threshold?: number;
|
|
451
|
+
}): Promise<SemanticSearchResponse>;
|
|
428
452
|
/**
|
|
429
453
|
* Associates an event with the current span. If event with such name never
|
|
430
454
|
* existed, Laminar will create a new event and infer its type from the value.
|
|
@@ -443,24 +467,42 @@ declare class Laminar {
|
|
|
443
467
|
static event(name: string, value?: AttributeValue, timestamp?: TimeInput): void;
|
|
444
468
|
/**
|
|
445
469
|
* Sets the session information for the current span and returns the
|
|
446
|
-
* context to use for the following spans.
|
|
470
|
+
* context to use for the following spans. Returns the result of the
|
|
471
|
+
* function execution, so can be used in an `await` statement.
|
|
447
472
|
*
|
|
448
473
|
* @param sessionId - The session ID to associate with the context.
|
|
449
|
-
* @param
|
|
450
|
-
* @returns The
|
|
474
|
+
* @param fn - Function to execute within the session context.
|
|
475
|
+
* @returns The result of the function execution.
|
|
451
476
|
*
|
|
452
477
|
* @example
|
|
453
|
-
* import {
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
* contextApi.with(context, () => {
|
|
457
|
-
* // Your code here
|
|
478
|
+
* import { Laminar, observe } from '@lmnr-ai/lmnr';
|
|
479
|
+
* const result = await Laminar.withSession("session1234", async () => {
|
|
480
|
+
* // Your code here
|
|
458
481
|
* });
|
|
459
482
|
*/
|
|
460
|
-
static
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
483
|
+
static withSession<T>(sessionId: string, fn: () => T): T;
|
|
484
|
+
/**
|
|
485
|
+
* Sets the metadata for the current span and returns the context to use for
|
|
486
|
+
* the following spans. Returns the result of the function execution, so can
|
|
487
|
+
* be used in an `await` statement.
|
|
488
|
+
*
|
|
489
|
+
* @param metadata - The metadata to associate with the context. Set of string key
|
|
490
|
+
* string value pairs.
|
|
491
|
+
* @param fn - Function to execute within the metadata context.
|
|
492
|
+
* @returns The result of the function execution.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* import { Laminar } from '@lmnr-ai/lmnr';
|
|
496
|
+
* const result = await Laminar.withMetadata(
|
|
497
|
+
* {
|
|
498
|
+
* "my_metadata_key": "my_metadata_value"
|
|
499
|
+
* },
|
|
500
|
+
* async () => {
|
|
501
|
+
* // Your code here
|
|
502
|
+
* }
|
|
503
|
+
* );
|
|
504
|
+
*/
|
|
505
|
+
static withMetadata<T>(metadata: Record<string, string>, fn: () => T): T;
|
|
464
506
|
/**
|
|
465
507
|
* Set attributes for the current span. Useful for manual
|
|
466
508
|
* instrumentation.
|
|
@@ -576,7 +618,8 @@ interface ObserveOptions {
|
|
|
576
618
|
* functions and methods to create spans.
|
|
577
619
|
*
|
|
578
620
|
* @param name - Name of the span. Function name is used if not specified.
|
|
579
|
-
* @param userId -
|
|
621
|
+
* @param userId - Deprecated. Use {@link Laminar.withMetadata} to set key-value pairs.
|
|
622
|
+
* User ID to associate with the span and the following context.
|
|
580
623
|
* @param sessionId - Session ID to associate with the span and the following context.
|
|
581
624
|
* @param traceType – Type of the trace. Unless it is within evaluation, it should be 'DEFAULT'.
|
|
582
625
|
* @param spanType - Type of the span. 'DEFAULT' is used if not specified. If the type is 'LLM',
|
package/dist/index.js
CHANGED
|
@@ -109,7 +109,6 @@ var SPAN_INSTRUMENTATION_SOURCE = "lmnr.span.instrumentation_source";
|
|
|
109
109
|
var OVERRIDE_PARENT_SPAN = "lmnr.internal.override_parent_span";
|
|
110
110
|
var ASSOCIATION_PROPERTIES = "lmnr.association.properties";
|
|
111
111
|
var SESSION_ID = "lmnr.association.properties.session_id";
|
|
112
|
-
var USER_ID = "lmnr.association.properties.user_id";
|
|
113
112
|
var ASSOCIATION_PROPERTIES_OVERRIDES = {
|
|
114
113
|
"span_type": SPAN_TYPE
|
|
115
114
|
};
|
|
@@ -712,6 +711,37 @@ var Laminar = class {
|
|
|
712
711
|
throw new Error(`Failed to parse response from pipeline ${pipeline}. Error: ${error}`);
|
|
713
712
|
}
|
|
714
713
|
}
|
|
714
|
+
/**
|
|
715
|
+
* Perform a semantic search on a dataset.
|
|
716
|
+
*
|
|
717
|
+
* @param query - The query string to search with.
|
|
718
|
+
* @param datasetId - The ID of the dataset to search in.
|
|
719
|
+
* @param limit - The maximum number of results to return.
|
|
720
|
+
* @param threshold - The minimum score for the results to be returned.
|
|
721
|
+
* @returns Response object containing the search results in descending order of relevance.
|
|
722
|
+
*/
|
|
723
|
+
static async semanticSearch({
|
|
724
|
+
query,
|
|
725
|
+
datasetId,
|
|
726
|
+
limit,
|
|
727
|
+
threshold
|
|
728
|
+
}) {
|
|
729
|
+
const body = JSON.stringify({
|
|
730
|
+
query,
|
|
731
|
+
datasetId,
|
|
732
|
+
limit,
|
|
733
|
+
threshold
|
|
734
|
+
});
|
|
735
|
+
const response = await fetch(`${this.baseHttpUrl}/v1/semantic-search`, {
|
|
736
|
+
method: "POST",
|
|
737
|
+
headers: this.getHeaders(),
|
|
738
|
+
body
|
|
739
|
+
});
|
|
740
|
+
if (!response.ok) {
|
|
741
|
+
throw new Error(`Failed to perform semantic search. Response: ${response.statusText}`);
|
|
742
|
+
}
|
|
743
|
+
return await response.json();
|
|
744
|
+
}
|
|
715
745
|
/**
|
|
716
746
|
* Associates an event with the current span. If event with such name never
|
|
717
747
|
* existed, Laminar will create a new event and infer its type from the value.
|
|
@@ -745,49 +775,81 @@ var Laminar = class {
|
|
|
745
775
|
}
|
|
746
776
|
/**
|
|
747
777
|
* Sets the session information for the current span and returns the
|
|
748
|
-
* context to use for the following spans.
|
|
778
|
+
* context to use for the following spans. Returns the result of the
|
|
779
|
+
* function execution, so can be used in an `await` statement.
|
|
749
780
|
*
|
|
750
781
|
* @param sessionId - The session ID to associate with the context.
|
|
751
|
-
* @param
|
|
752
|
-
* @returns The
|
|
782
|
+
* @param fn - Function to execute within the session context.
|
|
783
|
+
* @returns The result of the function execution.
|
|
753
784
|
*
|
|
754
785
|
* @example
|
|
755
|
-
* import {
|
|
756
|
-
*
|
|
757
|
-
*
|
|
758
|
-
* contextApi.with(context, () => {
|
|
759
|
-
* // Your code here
|
|
786
|
+
* import { Laminar, observe } from '@lmnr-ai/lmnr';
|
|
787
|
+
* const result = await Laminar.withSession("session1234", async () => {
|
|
788
|
+
* // Your code here
|
|
760
789
|
* });
|
|
761
790
|
*/
|
|
762
|
-
static
|
|
763
|
-
sessionId,
|
|
764
|
-
userId
|
|
765
|
-
}) {
|
|
791
|
+
static withSession(sessionId, fn) {
|
|
766
792
|
const currentSpan = import_api5.trace.getActiveSpan();
|
|
767
793
|
if (currentSpan !== void 0 && (0, import_api5.isSpanContextValid)(currentSpan.spanContext())) {
|
|
768
794
|
if (sessionId) {
|
|
769
|
-
currentSpan.setAttribute(SESSION_ID, sessionId);
|
|
770
|
-
}
|
|
771
|
-
if (userId) {
|
|
772
|
-
currentSpan.setAttribute(USER_ID, userId);
|
|
795
|
+
currentSpan.setAttribute(SESSION_ID, JSON.stringify(sessionId));
|
|
773
796
|
}
|
|
774
797
|
}
|
|
775
798
|
let associationProperties = {};
|
|
776
799
|
if (sessionId) {
|
|
777
|
-
associationProperties = { ...associationProperties, "session_id": sessionId };
|
|
778
|
-
}
|
|
779
|
-
if (userId) {
|
|
780
|
-
associationProperties = { ...associationProperties, "user_id": userId };
|
|
800
|
+
associationProperties = { ...associationProperties, "session_id": JSON.stringify(sessionId) };
|
|
781
801
|
}
|
|
782
802
|
let entityContext = import_api5.context.active();
|
|
783
803
|
const currentAssociationProperties = entityContext.getValue(ASSOCIATION_PROPERTIES_KEY);
|
|
784
|
-
if (associationProperties) {
|
|
804
|
+
if (associationProperties && Object.keys(associationProperties).length > 0) {
|
|
785
805
|
entityContext = entityContext.setValue(
|
|
786
806
|
ASSOCIATION_PROPERTIES_KEY,
|
|
787
807
|
{ ...currentAssociationProperties != null ? currentAssociationProperties : {}, ...associationProperties }
|
|
788
808
|
);
|
|
789
809
|
}
|
|
790
|
-
return entityContext;
|
|
810
|
+
return import_api5.context.with(entityContext, fn);
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Sets the metadata for the current span and returns the context to use for
|
|
814
|
+
* the following spans. Returns the result of the function execution, so can
|
|
815
|
+
* be used in an `await` statement.
|
|
816
|
+
*
|
|
817
|
+
* @param metadata - The metadata to associate with the context. Set of string key
|
|
818
|
+
* string value pairs.
|
|
819
|
+
* @param fn - Function to execute within the metadata context.
|
|
820
|
+
* @returns The result of the function execution.
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* import { Laminar } from '@lmnr-ai/lmnr';
|
|
824
|
+
* const result = await Laminar.withMetadata(
|
|
825
|
+
* {
|
|
826
|
+
* "my_metadata_key": "my_metadata_value"
|
|
827
|
+
* },
|
|
828
|
+
* async () => {
|
|
829
|
+
* // Your code here
|
|
830
|
+
* }
|
|
831
|
+
* );
|
|
832
|
+
*/
|
|
833
|
+
static withMetadata(metadata, fn) {
|
|
834
|
+
const currentSpan = import_api5.trace.getActiveSpan();
|
|
835
|
+
if (currentSpan !== void 0 && (0, import_api5.isSpanContextValid)(currentSpan.spanContext())) {
|
|
836
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
837
|
+
currentSpan.setAttribute(`${ASSOCIATION_PROPERTIES}.metadata.${key}`, JSON.stringify(value));
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
let metadataAttributes = {};
|
|
841
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
842
|
+
metadataAttributes = { ...metadataAttributes, [`metadata.${key}`]: JSON.stringify(value) };
|
|
843
|
+
}
|
|
844
|
+
let entityContext = import_api5.context.active();
|
|
845
|
+
const currentAssociationProperties = entityContext.getValue(ASSOCIATION_PROPERTIES_KEY);
|
|
846
|
+
if (metadataAttributes && Object.keys(metadataAttributes).length > 0) {
|
|
847
|
+
entityContext = entityContext.setValue(
|
|
848
|
+
ASSOCIATION_PROPERTIES_KEY,
|
|
849
|
+
{ ...currentAssociationProperties != null ? currentAssociationProperties : {}, ...metadataAttributes }
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
return import_api5.context.with(entityContext, fn);
|
|
791
853
|
}
|
|
792
854
|
/**
|
|
793
855
|
* Set attributes for the current span. Useful for manual
|
|
@@ -1062,6 +1124,7 @@ async function observe({
|
|
|
1062
1124
|
associationProperties = { ...associationProperties, "session_id": sessionId };
|
|
1063
1125
|
}
|
|
1064
1126
|
if (userId) {
|
|
1127
|
+
console.warn("`userId` is deprecated. Use `Laminar.withMetadata` to set key-value pairs.");
|
|
1065
1128
|
associationProperties = { ...associationProperties, "user_id": userId };
|
|
1066
1129
|
}
|
|
1067
1130
|
if (traceType) {
|