@mastra/lance 1.1.1 → 1.1.2-alpha.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @mastra/lance
2
2
 
3
+ ## 1.1.2-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Add optional `batchId`, `datasetId`, and `datasetItemId` fields to persisted scores so saved baseline scores can be grouped as one scoring pass and joined back to the dataset items they came from. ([#18331](https://github.com/mastra-ai/mastra/pull/18331))
8
+ - `scoreTrace()` accepts top-level `batchId`, `datasetId`, and `datasetItemId` when persisting a score for a stored trace.
9
+ - `ScoreRowData` and score save payloads now include nullable `batchId`, `datasetId`, and `datasetItemId`.
10
+ - Built-in stores with explicit score schema or attribute mappings now persist these provenance fields on saved scores.
11
+ - D1, DSQL, MSSQL, and Upstash score stores now apply additive provenance migrations or deterministic score ordering for persisted score reads.
12
+
13
+ ```ts
14
+ await scoreTrace({
15
+ storage,
16
+ scorer,
17
+ target: { traceId },
18
+ batchId: 'baseline-batch-1',
19
+ datasetId,
20
+ datasetItemId,
21
+ });
22
+ ```
23
+
24
+ - Added optional `organizationId` and `projectId` fields to scores for multi-tenant isolation. Scores can now be saved with tenancy metadata and the `listScoresBy*` methods accept a `filters` option to scope results by organization and project. ([#18331](https://github.com/mastra-ai/mastra/pull/18331))
25
+
26
+ ```ts
27
+ await storage.saveScore({ ...score, organizationId: 'org-a', projectId: 'proj-1' });
28
+
29
+ const result = await storage.listScoresByScorerId({
30
+ scorerId,
31
+ filters: { organizationId: 'org-a', projectId: 'proj-1' },
32
+ });
33
+ ```
34
+
35
+ `projectId` identifies the project scope, separate from `resourceId` which continues to mean the agent memory resource.
36
+
37
+ - Updated dependencies [[`9250acd`](https://github.com/mastra-ai/mastra/commit/9250acd1357f0f1f33d0dcca16f9655084c58eca), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`c64c2a8`](https://github.com/mastra-ai/mastra/commit/c64c2a8503a50252f9ca6b8e8c54cadee31b92a2), [`06e2680`](https://github.com/mastra-ai/mastra/commit/06e26806b51d2cbd858afdc66daa2b86ff3ba64a), [`1240f05`](https://github.com/mastra-ai/mastra/commit/1240f051c8e5371f1c014448bf37b1a1b9a05e47), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`24c10d3`](https://github.com/mastra-ai/mastra/commit/24c10d333e6649ac06075903aeeee13a933db3b3), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748), [`215f9b0`](https://github.com/mastra-ai/mastra/commit/215f9b0f3f3f6fc165edad360582dd4d3d7ea748)]:
38
+ - @mastra/core@1.49.0-alpha.5
39
+
3
40
  ## 1.1.1
4
41
 
5
42
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-lance
3
3
  description: Documentation for @mastra/lance. Use when working with @mastra/lance APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/lance"
6
- version: "1.1.1"
6
+ version: "1.1.2-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.1",
2
+ "version": "1.1.2-alpha.0",
3
3
  "package": "@mastra/lance",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Storing embeddings in a vector database
2
4
 
3
5
  After generating embeddings, you need to store them in a database that supports vector similarity search. Mastra provides a consistent interface for storing and querying embeddings across various vector databases.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # LanceDB storage
2
4
 
3
5
  The LanceDB storage implementation provides a high-performance storage solution using the LanceDB database system, which excels at handling both traditional data storage and vector operations.
@@ -1,3 +1,5 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
1
3
  # Lance vector store
2
4
 
3
5
  The LanceVectorStore class provides vector search using [LanceDB](https://lancedb.github.io/lancedb/), an embedded vector database built on the Lance columnar format. It offers efficient storage and fast similarity search for both local development and production deployments.
package/dist/index.cjs CHANGED
@@ -1641,6 +1641,16 @@ var StoreMemoryLance = class extends storage.MemoryStorage {
1641
1641
  throw new Error("Unexpected end of retry loop");
1642
1642
  }
1643
1643
  };
1644
+ function lanceStringLiteral(value) {
1645
+ return `'${value.replaceAll("'", "''")}'`;
1646
+ }
1647
+ function tenancyClause(filters) {
1648
+ const parts = [];
1649
+ if (filters?.organizationId !== void 0)
1650
+ parts.push(`\`organizationId\` = ${lanceStringLiteral(filters.organizationId)}`);
1651
+ if (filters?.projectId !== void 0) parts.push(`\`projectId\` = ${lanceStringLiteral(filters.projectId)}`);
1652
+ return parts.length ? ` AND ${parts.join(" AND ")}` : "";
1653
+ }
1644
1654
  var StoreScoresLance = class extends storage.ScoresStorage {
1645
1655
  client;
1646
1656
  #db;
@@ -1655,7 +1665,7 @@ var StoreScoresLance = class extends storage.ScoresStorage {
1655
1665
  await this.#db.alterTable({
1656
1666
  tableName: storage.TABLE_SCORERS,
1657
1667
  schema: storage.SCORERS_SCHEMA,
1658
- ifNotExists: ["spanId", "requestContext"]
1668
+ ifNotExists: ["spanId", "requestContext", "organizationId", "projectId", "batchId", "datasetId", "datasetItemId"]
1659
1669
  });
1660
1670
  }
1661
1671
  async dangerouslyClearAll() {
@@ -1721,7 +1731,7 @@ var StoreScoresLance = class extends storage.ScoresStorage {
1721
1731
  async getScoreById({ id }) {
1722
1732
  try {
1723
1733
  const table = await this.client.openTable(storage.TABLE_SCORERS);
1724
- const query = table.query().where(`id = '${id}'`).limit(1);
1734
+ const query = table.query().where(`id = ${lanceStringLiteral(id)}`).limit(1);
1725
1735
  const records = await query.toArray();
1726
1736
  if (records.length === 0) return null;
1727
1737
  return await this.transformScoreRow(records[0]);
@@ -1759,33 +1769,33 @@ var StoreScoresLance = class extends storage.ScoresStorage {
1759
1769
  pagination,
1760
1770
  entityId,
1761
1771
  entityType,
1762
- source
1772
+ source,
1773
+ filters
1763
1774
  }) {
1764
1775
  try {
1765
1776
  const { page, perPage: perPageInput } = pagination;
1766
1777
  const perPage = storage.normalizePerPage(perPageInput, 100);
1767
1778
  const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
1768
1779
  const table = await this.client.openTable(storage.TABLE_SCORERS);
1769
- let query = table.query().where(`\`scorerId\` = '${scorerId}'`);
1780
+ const conditions = [`\`scorerId\` = ${lanceStringLiteral(scorerId)}`];
1770
1781
  if (source) {
1771
- query = query.where(`\`source\` = '${source}'`);
1782
+ conditions.push(`\`source\` = ${lanceStringLiteral(source)}`);
1772
1783
  }
1773
1784
  if (entityId) {
1774
- query = query.where(`\`entityId\` = '${entityId}'`);
1785
+ conditions.push(`\`entityId\` = ${lanceStringLiteral(entityId)}`);
1775
1786
  }
1776
1787
  if (entityType) {
1777
- query = query.where(`\`entityType\` = '${entityType}'`);
1778
- }
1779
- let totalQuery = table.query().where(`\`scorerId\` = '${scorerId}'`);
1780
- if (source) {
1781
- totalQuery = totalQuery.where(`\`source\` = '${source}'`);
1788
+ conditions.push(`\`entityType\` = ${lanceStringLiteral(entityType)}`);
1782
1789
  }
1783
- if (entityId) {
1784
- totalQuery = totalQuery.where(`\`entityId\` = '${entityId}'`);
1790
+ if (filters?.organizationId !== void 0) {
1791
+ conditions.push(`\`organizationId\` = ${lanceStringLiteral(filters.organizationId)}`);
1785
1792
  }
1786
- if (entityType) {
1787
- totalQuery = totalQuery.where(`\`entityType\` = '${entityType}'`);
1793
+ if (filters?.projectId !== void 0) {
1794
+ conditions.push(`\`projectId\` = ${lanceStringLiteral(filters.projectId)}`);
1788
1795
  }
1796
+ const whereClause = conditions.join(" AND ");
1797
+ let query = table.query().where(whereClause);
1798
+ const totalQuery = table.query().where(whereClause);
1789
1799
  const allRecords = await totalQuery.toArray();
1790
1800
  const total = allRecords.length;
1791
1801
  const end = perPageInput === false ? total : start + perPage;
@@ -1819,17 +1829,18 @@ var StoreScoresLance = class extends storage.ScoresStorage {
1819
1829
  }
1820
1830
  async listScoresByRunId({
1821
1831
  runId,
1822
- pagination
1832
+ pagination,
1833
+ filters
1823
1834
  }) {
1824
1835
  try {
1825
1836
  const { page, perPage: perPageInput } = pagination;
1826
1837
  const perPage = storage.normalizePerPage(perPageInput, 100);
1827
1838
  const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
1828
1839
  const table = await this.client.openTable(storage.TABLE_SCORERS);
1829
- const allRecords = await table.query().where(`\`runId\` = '${runId}'`).toArray();
1840
+ const allRecords = await table.query().where(`\`runId\` = ${lanceStringLiteral(runId)}${tenancyClause(filters)}`).toArray();
1830
1841
  const total = allRecords.length;
1831
1842
  const end = perPageInput === false ? total : start + perPage;
1832
- let query = table.query().where(`\`runId\` = '${runId}'`);
1843
+ let query = table.query().where(`\`runId\` = ${lanceStringLiteral(runId)}${tenancyClause(filters)}`);
1833
1844
  if (perPageInput !== false) {
1834
1845
  query = query.limit(perPage);
1835
1846
  if (start > 0) query = query.offset(start);
@@ -1861,17 +1872,22 @@ var StoreScoresLance = class extends storage.ScoresStorage {
1861
1872
  async listScoresByEntityId({
1862
1873
  entityId,
1863
1874
  entityType,
1864
- pagination
1875
+ pagination,
1876
+ filters
1865
1877
  }) {
1866
1878
  try {
1867
1879
  const { page, perPage: perPageInput } = pagination;
1868
1880
  const perPage = storage.normalizePerPage(perPageInput, 100);
1869
1881
  const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
1870
1882
  const table = await this.client.openTable(storage.TABLE_SCORERS);
1871
- const allRecords = await table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`).toArray();
1883
+ const allRecords = await table.query().where(
1884
+ `\`entityId\` = ${lanceStringLiteral(entityId)} AND \`entityType\` = ${lanceStringLiteral(entityType)}${tenancyClause(filters)}`
1885
+ ).toArray();
1872
1886
  const total = allRecords.length;
1873
1887
  const end = perPageInput === false ? total : start + perPage;
1874
- let query = table.query().where(`\`entityId\` = '${entityId}' AND \`entityType\` = '${entityType}'`);
1888
+ let query = table.query().where(
1889
+ `\`entityId\` = ${lanceStringLiteral(entityId)} AND \`entityType\` = ${lanceStringLiteral(entityType)}${tenancyClause(filters)}`
1890
+ );
1875
1891
  if (perPageInput !== false) {
1876
1892
  query = query.limit(perPage);
1877
1893
  if (start > 0) query = query.offset(start);
@@ -1903,17 +1919,22 @@ var StoreScoresLance = class extends storage.ScoresStorage {
1903
1919
  async listScoresBySpan({
1904
1920
  traceId,
1905
1921
  spanId,
1906
- pagination
1922
+ pagination,
1923
+ filters
1907
1924
  }) {
1908
1925
  try {
1909
1926
  const { page, perPage: perPageInput } = pagination;
1910
1927
  const perPage = storage.normalizePerPage(perPageInput, 100);
1911
1928
  const { offset: start, perPage: perPageForResponse } = storage.calculatePagination(page, perPageInput, perPage);
1912
1929
  const table = await this.client.openTable(storage.TABLE_SCORERS);
1913
- const allRecords = await table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`).toArray();
1930
+ const allRecords = await table.query().where(
1931
+ `\`traceId\` = ${lanceStringLiteral(traceId)} AND \`spanId\` = ${lanceStringLiteral(spanId)}${tenancyClause(filters)}`
1932
+ ).toArray();
1914
1933
  const total = allRecords.length;
1915
1934
  const end = perPageInput === false ? total : start + perPage;
1916
- let query = table.query().where(`\`traceId\` = '${traceId}' AND \`spanId\` = '${spanId}'`);
1935
+ let query = table.query().where(
1936
+ `\`traceId\` = ${lanceStringLiteral(traceId)} AND \`spanId\` = ${lanceStringLiteral(spanId)}${tenancyClause(filters)}`
1937
+ );
1917
1938
  if (perPageInput !== false) {
1918
1939
  query = query.limit(perPage);
1919
1940
  if (start > 0) query = query.offset(start);