chromadb 3.3.3 → 3.4.1

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.
@@ -1,3 +1,5 @@
1
+ import { createClient } from '@hey-api/client-fetch';
2
+
1
3
  type BoolInvertedIndexConfig$1 = {
2
4
  [key: string]: never;
3
5
  };
@@ -1515,6 +1517,17 @@ declare class ChromaClient {
1515
1517
  embeddingFunction?: EmbeddingFunction | null;
1516
1518
  schema?: Schema;
1517
1519
  }): Promise<Collection>;
1520
+ /**
1521
+ * Returns a lightweight collection handle for the given collection ID.
1522
+ * The handle supports operations that don't require an embedding function
1523
+ * or schema (e.g., add with pre-computed embeddings, get, delete, count, search).
1524
+ * Operations that require an embedding function will throw a clear error
1525
+ * directing you to use {@link getCollection} instead.
1526
+ * @param id - The collection ID
1527
+ * @returns A Collection handle for the given ID
1528
+ * @throws ChromaValueError if tenant or database are not set on the client
1529
+ */
1530
+ collection(id: string): Collection;
1518
1531
  /**
1519
1532
  * Deletes a collection and all its data.
1520
1533
  * @param options - Deletion options
@@ -1672,6 +1685,11 @@ interface Collection {
1672
1685
  fork({ name }: {
1673
1686
  name: string;
1674
1687
  }): Promise<Collection>;
1688
+ /**
1689
+ * Gets the number of forks for this collection.
1690
+ * @returns Promise resolving to the number of forks
1691
+ */
1692
+ forkCount(): Promise<number>;
1675
1693
  /**
1676
1694
  * Updates existing records in the collection.
1677
1695
  * @param args - Record data to update
@@ -1738,6 +1756,209 @@ interface Collection {
1738
1756
  */
1739
1757
  getIndexingStatus(): Promise<IndexingStatus>;
1740
1758
  }
1759
+ /**
1760
+ * Arguments for creating a Collection instance.
1761
+ */
1762
+ interface CollectionArgs {
1763
+ /** ChromaDB client instance */
1764
+ chromaClient: ChromaClient;
1765
+ /** HTTP API client */
1766
+ apiClient: ReturnType<typeof createClient>;
1767
+ /** Collection name */
1768
+ name: string;
1769
+ /** Collection ID */
1770
+ id: string;
1771
+ /** Tenant name */
1772
+ tenant: string;
1773
+ /** Database name */
1774
+ database: string;
1775
+ /** Embedding function for the collection */
1776
+ embeddingFunction?: EmbeddingFunction;
1777
+ /** Collection configuration */
1778
+ configuration: CollectionConfiguration;
1779
+ /** Optional collection metadata */
1780
+ metadata?: CollectionMetadata;
1781
+ /** Optional schema returned by the server */
1782
+ schema?: Schema;
1783
+ }
1784
+ /**
1785
+ * Implementation of CollectionAPI for ID-based collection operations.
1786
+ * Provides core functionality for interacting with collections using their ID.
1787
+ */
1788
+ declare class CollectionImpl implements Collection {
1789
+ protected readonly chromaClient: ChromaClient;
1790
+ protected readonly apiClient: ReturnType<typeof createClient>;
1791
+ readonly id: string;
1792
+ readonly tenant: string;
1793
+ readonly database: string;
1794
+ private _name;
1795
+ private _metadata;
1796
+ private _configuration;
1797
+ protected _embeddingFunction: EmbeddingFunction | undefined;
1798
+ protected _schema: Schema | undefined;
1799
+ /**
1800
+ * Creates a new CollectionAPIImpl instance.
1801
+ * @param options - Configuration for the collection API
1802
+ */
1803
+ constructor({ chromaClient, apiClient, id, tenant, database, name, metadata, configuration, embeddingFunction, schema, }: CollectionArgs);
1804
+ get name(): string;
1805
+ private set name(value);
1806
+ get configuration(): CollectionConfiguration;
1807
+ private set configuration(value);
1808
+ get metadata(): CollectionMetadata | undefined;
1809
+ private set metadata(value);
1810
+ get embeddingFunction(): EmbeddingFunction | undefined;
1811
+ protected set embeddingFunction(embeddingFunction: EmbeddingFunction | undefined);
1812
+ get schema(): Schema | undefined;
1813
+ protected set schema(schema: Schema | undefined);
1814
+ protected path(): Promise<{
1815
+ tenant: string;
1816
+ database: string;
1817
+ collection_id: string;
1818
+ }>;
1819
+ private embed;
1820
+ private sparseEmbed;
1821
+ private getSparseEmbeddingTargets;
1822
+ private applySparseEmbeddingsToMetadatas;
1823
+ private embedKnnLiteral;
1824
+ private embedRankLiteral;
1825
+ private embedSearchPayload;
1826
+ private getSchemaEmbeddingFunction;
1827
+ private prepareRecords;
1828
+ private validateGet;
1829
+ private prepareQuery;
1830
+ private validateDelete;
1831
+ count(options?: {
1832
+ readLevel?: ReadLevel;
1833
+ }): Promise<number>;
1834
+ add({ ids, embeddings, metadatas, documents, uris, }: {
1835
+ ids: string[];
1836
+ embeddings?: number[][];
1837
+ metadatas?: Metadata[];
1838
+ documents?: string[];
1839
+ uris?: string[];
1840
+ }): Promise<void>;
1841
+ get<TMeta extends Metadata = Metadata>(args?: Partial<{
1842
+ ids?: string[];
1843
+ where?: Where;
1844
+ limit?: number;
1845
+ offset?: number;
1846
+ whereDocument?: WhereDocument;
1847
+ include?: Include[];
1848
+ }>): Promise<GetResult<TMeta>>;
1849
+ peek({ limit }: {
1850
+ limit?: number;
1851
+ }): Promise<GetResult>;
1852
+ query<TMeta extends Metadata = Metadata>({ queryEmbeddings, queryTexts, queryURIs, ids, nResults, where, whereDocument, include, }: {
1853
+ queryEmbeddings?: number[][];
1854
+ queryTexts?: string[];
1855
+ queryURIs?: string[];
1856
+ ids?: string[];
1857
+ nResults?: number;
1858
+ where?: Where;
1859
+ whereDocument?: WhereDocument;
1860
+ include?: Include[];
1861
+ }): Promise<QueryResult<TMeta>>;
1862
+ search(searches: SearchLike | SearchLike[], options?: {
1863
+ readLevel?: ReadLevel;
1864
+ }): Promise<SearchResult>;
1865
+ modify({ name, metadata, configuration, }: {
1866
+ name?: string;
1867
+ metadata?: CollectionMetadata;
1868
+ configuration?: UpdateCollectionConfiguration;
1869
+ }): Promise<void>;
1870
+ fork({ name }: {
1871
+ name: string;
1872
+ }): Promise<Collection>;
1873
+ forkCount(): Promise<number>;
1874
+ update({ ids, embeddings, metadatas, documents, uris, }: {
1875
+ ids: string[];
1876
+ embeddings?: number[][];
1877
+ metadatas?: Metadata[];
1878
+ documents?: string[];
1879
+ uris?: string[];
1880
+ }): Promise<void>;
1881
+ upsert({ ids, embeddings, metadatas, documents, uris, }: {
1882
+ ids: string[];
1883
+ embeddings?: number[][];
1884
+ metadatas?: Metadata[];
1885
+ documents?: string[];
1886
+ uris?: string[];
1887
+ }): Promise<void>;
1888
+ delete({ ids, where, whereDocument, limit, }: {
1889
+ ids?: string[];
1890
+ where?: Where;
1891
+ whereDocument?: WhereDocument;
1892
+ limit?: number;
1893
+ }): Promise<DeleteResult>;
1894
+ getIndexingStatus(): Promise<IndexingStatus>;
1895
+ }
1896
+ /**
1897
+ * Arguments for creating a CollectionHandle instance.
1898
+ */
1899
+ interface CollectionHandleArgs {
1900
+ /** ChromaDB client instance */
1901
+ chromaClient: ChromaClient;
1902
+ /** HTTP API client */
1903
+ apiClient: ReturnType<typeof createClient>;
1904
+ /** Collection ID */
1905
+ id: string;
1906
+ /** Tenant name */
1907
+ tenant: string;
1908
+ /** Database name */
1909
+ database: string;
1910
+ }
1911
+ /**
1912
+ * A lightweight collection handle that holds only the collection ID and
1913
+ * client context. Supports operations that don't require an embedding
1914
+ * function or schema. Obtained via {@link ChromaClient.collection}.
1915
+ */
1916
+ declare class CollectionHandle extends CollectionImpl {
1917
+ constructor({ chromaClient, apiClient, id, tenant, database }: CollectionHandleArgs);
1918
+ add(args: {
1919
+ ids: string[];
1920
+ embeddings?: number[][];
1921
+ metadatas?: Metadata[];
1922
+ documents?: string[];
1923
+ uris?: string[];
1924
+ }): Promise<void>;
1925
+ update(args: {
1926
+ ids: string[];
1927
+ embeddings?: number[][];
1928
+ metadatas?: Metadata[];
1929
+ documents?: string[];
1930
+ uris?: string[];
1931
+ }): Promise<void>;
1932
+ upsert(args: {
1933
+ ids: string[];
1934
+ embeddings?: number[][];
1935
+ metadatas?: Metadata[];
1936
+ documents?: string[];
1937
+ uris?: string[];
1938
+ }): Promise<void>;
1939
+ query<TMeta extends Metadata = Metadata>(args: {
1940
+ queryEmbeddings?: number[][];
1941
+ queryTexts?: string[];
1942
+ queryURIs?: string[];
1943
+ ids?: string[];
1944
+ nResults?: number;
1945
+ where?: Where;
1946
+ whereDocument?: WhereDocument;
1947
+ include?: Include[];
1948
+ }): Promise<QueryResult<TMeta>>;
1949
+ search(searches: SearchLike | SearchLike[], options?: {
1950
+ readLevel?: ReadLevel;
1951
+ }): Promise<SearchResult>;
1952
+ modify(_args: {
1953
+ name?: string;
1954
+ metadata?: CollectionMetadata;
1955
+ configuration?: UpdateCollectionConfiguration;
1956
+ }): Promise<void>;
1957
+ fork(_args: {
1958
+ name: string;
1959
+ }): Promise<Collection>;
1960
+ private hasStringKnnQuery;
1961
+ }
1741
1962
 
1742
1963
  declare function withChroma(userNextConfig?: any): any;
1743
1964
 
@@ -1956,4 +2177,4 @@ declare class ChromaRateLimitError extends Error {
1956
2177
  }
1957
2178
  declare function createErrorByType(type: string, message: string): InvalidCollectionError | InvalidArgumentError | undefined;
1958
2179
 
1959
- export { Abs, AdminClient, type AdminClientArgs, AdminCloudClient, Aggregate, type AggregateInput, type AggregateJSON, type AnyEmbeddingFunction, type BaseRecordSet, BoolInvertedIndexConfig, BoolInvertedIndexType, BoolValueType, ChromaClient, type ChromaClientArgs, ChromaClientError, ChromaConnectionError, ChromaError, ChromaForbiddenError, ChromaNotFoundError, ChromaQuotaExceededError, ChromaRateLimitError, ChromaServerError, ChromaUnauthorizedError, ChromaUniqueError, ChromaValueError, CloudClient, Cmek, CmekProvider, type Collection, type CollectionConfiguration, type CollectionMetadata, type CreateCollectionConfiguration, DOCUMENT_KEY, type DeleteResult, Div, EMBEDDING_KEY, type EmbeddingFunction, type EmbeddingFunctionClass, type EmbeddingFunctionSpace, Exp, FloatInvertedIndexConfig, FloatInvertedIndexType, FloatListValueType, FloatValueType, FtsIndexConfig, FtsIndexType, GetResult, GroupBy, type GroupByInput, type GroupByJSON, type HNSWConfiguration, IncludeEnum, type IndexConfig, type IndexingStatus, IntInvertedIndexConfig, IntInvertedIndexType, IntValueType, InvalidArgumentError, InvalidCollectionError, K, Key, type KeyFactory, Knn, type KnnOptions, Limit, type LimitInput, type LimitOptions, type ListDatabasesArgs, Log, Max, MaxK, type Metadata, type MetadataScalar, Min, MinK, Mul, type PreparedInsertRecordSet, type PreparedRecordSet, type QueryRecordSet, QueryResult, type QueryRowResult, RankExpression, type RankInput, type RankLiteral, ReadLevel, type RecordSet, Rrf, type RrfOptions, Schema, Search, type SearchInit, type SearchLike, SearchResult, type SearchResultRow, Select, type SelectInput, type SelectKeyInput, type SparseEmbeddingFunction, type SparseEmbeddingFunctionClass, type SparseVector, SparseVectorIndexConfig, type SparseVectorIndexConfigOptions, SparseVectorIndexType, SparseVectorValueType, StringInvertedIndexConfig, StringInvertedIndexType, StringValueType, Sub, Sum, type UpdateCollectionConfiguration, type UpdateHNSWConfiguration, type UpdateSPANNConfiguration, type UserIdentity, Val, ValueTypes, VectorIndexConfig, type VectorIndexConfigOptions, VectorIndexType, type Where, type WhereDocument, WhereExpression, type WhereInput, type WhereJSON, baseRecordSetFields, createErrorByType, getDefaultEFConfig, getEmbeddingFunction, getSparseEmbeddingFunction, knownEmbeddingFunctions, knownSparseEmbeddingFunctions, processCreateCollectionConfig, processUpdateCollectionConfig, recordSetFields, registerEmbeddingFunction, registerSparseEmbeddingFunction, serializeEmbeddingFunction, toSearch, withChroma };
2180
+ export { Abs, AdminClient, type AdminClientArgs, AdminCloudClient, Aggregate, type AggregateInput, type AggregateJSON, type AnyEmbeddingFunction, type BaseRecordSet, BoolInvertedIndexConfig, BoolInvertedIndexType, BoolValueType, ChromaClient, type ChromaClientArgs, ChromaClientError, ChromaConnectionError, ChromaError, ChromaForbiddenError, ChromaNotFoundError, ChromaQuotaExceededError, ChromaRateLimitError, ChromaServerError, ChromaUnauthorizedError, ChromaUniqueError, ChromaValueError, CloudClient, Cmek, CmekProvider, type Collection, type CollectionConfiguration, CollectionHandle, type CollectionMetadata, type CreateCollectionConfiguration, DOCUMENT_KEY, type DeleteResult, Div, EMBEDDING_KEY, type EmbeddingFunction, type EmbeddingFunctionClass, type EmbeddingFunctionSpace, Exp, FloatInvertedIndexConfig, FloatInvertedIndexType, FloatListValueType, FloatValueType, FtsIndexConfig, FtsIndexType, GetResult, GroupBy, type GroupByInput, type GroupByJSON, type HNSWConfiguration, IncludeEnum, type IndexConfig, type IndexingStatus, IntInvertedIndexConfig, IntInvertedIndexType, IntValueType, InvalidArgumentError, InvalidCollectionError, K, Key, type KeyFactory, Knn, type KnnOptions, Limit, type LimitInput, type LimitOptions, type ListDatabasesArgs, Log, Max, MaxK, type Metadata, type MetadataScalar, Min, MinK, Mul, type PreparedInsertRecordSet, type PreparedRecordSet, type QueryRecordSet, QueryResult, type QueryRowResult, RankExpression, type RankInput, type RankLiteral, ReadLevel, type RecordSet, Rrf, type RrfOptions, Schema, Search, type SearchInit, type SearchLike, SearchResult, type SearchResultRow, Select, type SelectInput, type SelectKeyInput, type SparseEmbeddingFunction, type SparseEmbeddingFunctionClass, type SparseVector, SparseVectorIndexConfig, type SparseVectorIndexConfigOptions, SparseVectorIndexType, SparseVectorValueType, StringInvertedIndexConfig, StringInvertedIndexType, StringValueType, Sub, Sum, type UpdateCollectionConfiguration, type UpdateHNSWConfiguration, type UpdateSPANNConfiguration, type UserIdentity, Val, ValueTypes, VectorIndexConfig, type VectorIndexConfigOptions, VectorIndexType, type Where, type WhereDocument, WhereExpression, type WhereInput, type WhereJSON, baseRecordSetFields, createErrorByType, getDefaultEFConfig, getEmbeddingFunction, getSparseEmbeddingFunction, knownEmbeddingFunctions, knownSparseEmbeddingFunctions, processCreateCollectionConfig, processUpdateCollectionConfig, recordSetFields, registerEmbeddingFunction, registerSparseEmbeddingFunction, serializeEmbeddingFunction, toSearch, withChroma };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chromadb",
3
- "version": "3.3.3",
3
+ "version": "3.4.1",
4
4
  "description": "A JavaScript interface for chroma",
5
5
  "keywords": [
6
6
  "chroma",
@@ -60,11 +60,11 @@
60
60
  "@chroma-core/default-embed": "^0.1.9"
61
61
  },
62
62
  "optionalDependencies": {
63
- "chromadb-js-bindings-darwin-arm64": "^1.3.1",
64
- "chromadb-js-bindings-darwin-x64": "^1.3.1",
65
- "chromadb-js-bindings-linux-arm64-gnu": "^1.3.1",
66
- "chromadb-js-bindings-linux-x64-gnu": "^1.3.1",
67
- "chromadb-js-bindings-win32-x64-msvc": "^1.3.1"
63
+ "chromadb-js-bindings-darwin-arm64": "^1.3.2",
64
+ "chromadb-js-bindings-darwin-x64": "^1.3.2",
65
+ "chromadb-js-bindings-linux-arm64-gnu": "^1.3.2",
66
+ "chromadb-js-bindings-linux-x64-gnu": "^1.3.2",
67
+ "chromadb-js-bindings-win32-x64-msvc": "^1.3.2"
68
68
  },
69
69
  "engines": {
70
70
  "node": ">=20"
@@ -1,7 +1,7 @@
1
1
  // This file is auto-generated by @hey-api/openapi-ts
2
2
 
3
3
  import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
4
- import type { GetUserIdentityData, GetUserIdentityResponse2, GetUserIdentityError, GetCollectionByCrnData, GetCollectionByCrnResponse, GetCollectionByCrnError, HealthcheckData, HealthcheckResponse, HealthcheckError, HeartbeatData, HeartbeatResponse2, HeartbeatError, PreFlightChecksData, PreFlightChecksResponse, PreFlightChecksError, ResetData, ResetResponse, ResetError, CreateTenantData, CreateTenantResponse2, CreateTenantError, GetTenantData, GetTenantResponse2, GetTenantError, UpdateTenantData, UpdateTenantResponse2, UpdateTenantError, ListDatabasesData, ListDatabasesResponse, ListDatabasesError, CreateDatabaseData, CreateDatabaseResponse2, CreateDatabaseError, DeleteDatabaseData, DeleteDatabaseResponse2, DeleteDatabaseError, GetDatabaseData, GetDatabaseResponse, GetDatabaseError, ListCollectionsData, ListCollectionsResponse, ListCollectionsError, CreateCollectionData, CreateCollectionResponse, CreateCollectionError, DeleteCollectionData, DeleteCollectionResponse2, DeleteCollectionError, GetCollectionData, GetCollectionResponse, GetCollectionError, UpdateCollectionData, UpdateCollectionResponse2, UpdateCollectionError, CollectionAddData, CollectionAddResponse, DetachFunctionData, DetachFunctionResponse2, DetachFunctionError, CollectionCountData, CollectionCountResponse, CollectionCountError, CollectionDeleteData, CollectionDeleteResponse, CollectionDeleteError, ForkCollectionData, ForkCollectionResponse, ForkCollectionError, AttachFunctionData, AttachFunctionResponse2, AttachFunctionError, GetAttachedFunctionData, GetAttachedFunctionResponse2, GetAttachedFunctionError, CollectionGetData, CollectionGetResponse, CollectionGetError, IndexingStatusData, IndexingStatusResponse, IndexingStatusError, CollectionQueryData, CollectionQueryResponse, CollectionQueryError, CollectionSearchData, CollectionSearchResponse, CollectionSearchError, CollectionUpdateData, CollectionUpdateResponse, CollectionUpsertData, CollectionUpsertResponse, CollectionUpsertError, CountCollectionsData, CountCollectionsResponse, CountCollectionsError, VersionData, VersionResponse } from './types.gen';
4
+ import type { GetUserIdentityData, GetUserIdentityResponse2, GetUserIdentityError, GetCollectionByCrnData, GetCollectionByCrnResponse, GetCollectionByCrnError, HealthcheckData, HealthcheckResponse, HealthcheckError, HeartbeatData, HeartbeatResponse2, HeartbeatError, PreFlightChecksData, PreFlightChecksResponse, PreFlightChecksError, ResetData, ResetResponse, ResetError, CreateTenantData, CreateTenantResponse2, CreateTenantError, GetTenantData, GetTenantResponse2, GetTenantError, UpdateTenantData, UpdateTenantResponse2, UpdateTenantError, ListDatabasesData, ListDatabasesResponse, ListDatabasesError, CreateDatabaseData, CreateDatabaseResponse2, CreateDatabaseError, DeleteDatabaseData, DeleteDatabaseResponse2, DeleteDatabaseError, GetDatabaseData, GetDatabaseResponse, GetDatabaseError, ListCollectionsData, ListCollectionsResponse, ListCollectionsError, CreateCollectionData, CreateCollectionResponse, CreateCollectionError, DeleteCollectionData, DeleteCollectionResponse2, DeleteCollectionError, GetCollectionData, GetCollectionResponse, GetCollectionError, UpdateCollectionData, UpdateCollectionResponse2, UpdateCollectionError, CollectionAddData, CollectionAddResponse, DetachFunctionData, DetachFunctionResponse2, DetachFunctionError, CollectionCountData, CollectionCountResponse, CollectionCountError, CollectionDeleteData, CollectionDeleteResponse, CollectionDeleteError, ForkCollectionData, ForkCollectionResponse, ForkCollectionError, ForkCountData, ForkCountResponse2, ForkCountError, AttachFunctionData, AttachFunctionResponse2, AttachFunctionError, GetAttachedFunctionData, GetAttachedFunctionResponse2, GetAttachedFunctionError, CollectionGetData, CollectionGetResponse, CollectionGetError, IndexingStatusData, IndexingStatusResponse, IndexingStatusError, CollectionQueryData, CollectionQueryResponse, CollectionQueryError, CollectionSearchData, CollectionSearchResponse, CollectionSearchError, CollectionUpdateData, CollectionUpdateResponse, CollectionUpsertData, CollectionUpsertResponse, CollectionUpsertError, CountCollectionsData, CountCollectionsResponse, CountCollectionsError, VersionData, VersionResponse } from './types.gen';
5
5
  import { client as _heyApiClient } from './client.gen';
6
6
 
7
7
  export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
@@ -170,6 +170,23 @@ export class CollectionService {
170
170
  });
171
171
  }
172
172
 
173
+ /**
174
+ * Get fork count
175
+ * Returns the number of forks for a collection.
176
+ */
177
+ public static forkCount<ThrowOnError extends boolean = true>(options: Options<ForkCountData, ThrowOnError>) {
178
+ return (options.client ?? _heyApiClient).get<ForkCountResponse2, ForkCountError, ThrowOnError>({
179
+ security: [
180
+ {
181
+ name: 'x-chroma-token',
182
+ type: 'apiKey'
183
+ }
184
+ ],
185
+ url: '/api/v2/tenants/{tenant}/databases/{database}/collections/{collection_id}/fork_count',
186
+ ...options
187
+ });
188
+ }
189
+
173
190
  /**
174
191
  * Get number of collections
175
192
  * Returns the total number of collections in a database.
@@ -260,6 +260,16 @@ export type ForkCollectionPayload = {
260
260
  new_name: string;
261
261
  };
262
262
 
263
+ /**
264
+ * Response containing the fork count for a collection.
265
+ */
266
+ export type ForkCountResponse = {
267
+ /**
268
+ * The number of forks for this collection.
269
+ */
270
+ count: number;
271
+ };
272
+
263
273
  export type FtsIndexConfig = {
264
274
  [key: string]: never;
265
275
  };
@@ -1663,6 +1673,52 @@ export type ForkCollectionResponses = {
1663
1673
 
1664
1674
  export type ForkCollectionResponse = ForkCollectionResponses[keyof ForkCollectionResponses];
1665
1675
 
1676
+ export type ForkCountData = {
1677
+ body?: never;
1678
+ path: {
1679
+ /**
1680
+ * Tenant UUID
1681
+ */
1682
+ tenant: string;
1683
+ /**
1684
+ * Database name
1685
+ */
1686
+ database: string;
1687
+ /**
1688
+ * Collection UUID
1689
+ */
1690
+ collection_id: string;
1691
+ };
1692
+ query?: never;
1693
+ url: '/api/v2/tenants/{tenant}/databases/{database}/collections/{collection_id}/fork_count';
1694
+ };
1695
+
1696
+ export type ForkCountErrors = {
1697
+ /**
1698
+ * Unauthorized
1699
+ */
1700
+ 401: ErrorResponse;
1701
+ /**
1702
+ * Collection not found
1703
+ */
1704
+ 404: ErrorResponse;
1705
+ /**
1706
+ * Server error
1707
+ */
1708
+ 500: ErrorResponse;
1709
+ };
1710
+
1711
+ export type ForkCountError = ForkCountErrors[keyof ForkCountErrors];
1712
+
1713
+ export type ForkCountResponses = {
1714
+ /**
1715
+ * Fork count retrieved successfully
1716
+ */
1717
+ 200: ForkCountResponse;
1718
+ };
1719
+
1720
+ export type ForkCountResponse2 = ForkCountResponses[keyof ForkCountResponses];
1721
+
1666
1722
  export type AttachFunctionData = {
1667
1723
  /**
1668
1724
  * Function attachment request
@@ -14,7 +14,7 @@ import {
14
14
  ChecklistResponse,
15
15
  } from "./api";
16
16
  import { CollectionMetadata, UserIdentity } from "./types";
17
- import { Collection, CollectionImpl } from "./collection";
17
+ import { Collection, CollectionHandle, CollectionImpl } from "./collection";
18
18
  import { EmbeddingFunction, getEmbeddingFunction } from "./embedding-function";
19
19
  import { chromaFetch } from "./chroma-fetch";
20
20
  import * as process from "node:process";
@@ -538,6 +538,33 @@ export class ChromaClient {
538
538
  });
539
539
  }
540
540
 
541
+ /**
542
+ * Returns a lightweight collection handle for the given collection ID.
543
+ * The handle supports operations that don't require an embedding function
544
+ * or schema (e.g., add with pre-computed embeddings, get, delete, count, search).
545
+ * Operations that require an embedding function will throw a clear error
546
+ * directing you to use {@link getCollection} instead.
547
+ * @param id - The collection ID
548
+ * @returns A Collection handle for the given ID
549
+ * @throws ChromaValueError if tenant or database are not set on the client
550
+ */
551
+ public collection(id: string): Collection {
552
+ if (!this._tenant || !this._database) {
553
+ throw new ChromaValueError(
554
+ "tenant and database must be set on the client before calling collection(). " +
555
+ "Provide them in the ChromaClient constructor or use getCollection() instead.",
556
+ );
557
+ }
558
+
559
+ return new CollectionHandle({
560
+ chromaClient: this,
561
+ apiClient: this.apiClient,
562
+ id,
563
+ tenant: this._tenant,
564
+ database: this._database,
565
+ });
566
+ }
567
+
541
568
  /**
542
569
  * Deletes a collection and all its data.
543
570
  * @param options - Deletion options
package/src/cli.ts CHANGED
@@ -53,10 +53,6 @@ const main = async () => {
53
53
  return;
54
54
  }
55
55
 
56
- process.on("SIGINT", () => {
57
- process.exit(0);
58
- });
59
-
60
56
  binding.cli(["chroma", ...args]);
61
57
  };
62
58
 
package/src/collection.ts CHANGED
@@ -167,6 +167,11 @@ export interface Collection {
167
167
  * @returns Promise resolving to the new Collection instance
168
168
  */
169
169
  fork({ name }: { name: string }): Promise<Collection>;
170
+ /**
171
+ * Gets the number of forks for this collection.
172
+ * @returns Promise resolving to the number of forks
173
+ */
174
+ forkCount(): Promise<number>;
170
175
  /**
171
176
  * Updates existing records in the collection.
172
177
  * @param args - Record data to update
@@ -1028,6 +1033,15 @@ export class CollectionImpl implements Collection {
1028
1033
  });
1029
1034
  }
1030
1035
 
1036
+ public async forkCount(): Promise<number> {
1037
+ const { data } = await CollectionService.forkCount({
1038
+ client: this.apiClient,
1039
+ path: await this.path(),
1040
+ });
1041
+
1042
+ return data.count;
1043
+ }
1044
+
1031
1045
  public async update({
1032
1046
  ids,
1033
1047
  embeddings,
@@ -1141,3 +1155,144 @@ export class CollectionImpl implements Collection {
1141
1155
  return data;
1142
1156
  }
1143
1157
  }
1158
+
1159
+ /**
1160
+ * Arguments for creating a CollectionHandle instance.
1161
+ */
1162
+ export interface CollectionHandleArgs {
1163
+ /** ChromaDB client instance */
1164
+ chromaClient: ChromaClient;
1165
+ /** HTTP API client */
1166
+ apiClient: ReturnType<typeof createClient>;
1167
+ /** Collection ID */
1168
+ id: string;
1169
+ /** Tenant name */
1170
+ tenant: string;
1171
+ /** Database name */
1172
+ database: string;
1173
+ }
1174
+
1175
+ const HANDLE_EMBEDDING_ERROR =
1176
+ "This operation requires an embedding function, which is not available on " +
1177
+ "a collection obtained via client.collection(id). Provide pre-computed " +
1178
+ "embeddings directly, or use client.getCollection() to get a full " +
1179
+ "collection with embedding support.";
1180
+
1181
+ const HANDLE_NOT_SUPPORTED_ERROR =
1182
+ "is not supported on a collection obtained via client.collection(id). " +
1183
+ "Use client.getCollection() to get a full collection instance.";
1184
+
1185
+ /**
1186
+ * A lightweight collection handle that holds only the collection ID and
1187
+ * client context. Supports operations that don't require an embedding
1188
+ * function or schema. Obtained via {@link ChromaClient.collection}.
1189
+ */
1190
+ export class CollectionHandle extends CollectionImpl {
1191
+ constructor({ chromaClient, apiClient, id, tenant, database }: CollectionHandleArgs) {
1192
+ super({
1193
+ chromaClient,
1194
+ apiClient,
1195
+ id,
1196
+ tenant,
1197
+ database,
1198
+ name: "",
1199
+ configuration: {},
1200
+ });
1201
+ }
1202
+
1203
+ public override async add(args: {
1204
+ ids: string[];
1205
+ embeddings?: number[][];
1206
+ metadatas?: Metadata[];
1207
+ documents?: string[];
1208
+ uris?: string[];
1209
+ }): Promise<void> {
1210
+ if (!args.embeddings) {
1211
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
1212
+ }
1213
+ return super.add(args);
1214
+ }
1215
+
1216
+ public override async update(args: {
1217
+ ids: string[];
1218
+ embeddings?: number[][];
1219
+ metadatas?: Metadata[];
1220
+ documents?: string[];
1221
+ uris?: string[];
1222
+ }): Promise<void> {
1223
+ if (!args.embeddings && args.documents) {
1224
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
1225
+ }
1226
+ return super.update(args);
1227
+ }
1228
+
1229
+ public override async upsert(args: {
1230
+ ids: string[];
1231
+ embeddings?: number[][];
1232
+ metadatas?: Metadata[];
1233
+ documents?: string[];
1234
+ uris?: string[];
1235
+ }): Promise<void> {
1236
+ if (!args.embeddings) {
1237
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
1238
+ }
1239
+ return super.upsert(args);
1240
+ }
1241
+
1242
+ public override async query<TMeta extends Metadata = Metadata>(args: {
1243
+ queryEmbeddings?: number[][];
1244
+ queryTexts?: string[];
1245
+ queryURIs?: string[];
1246
+ ids?: string[];
1247
+ nResults?: number;
1248
+ where?: Where;
1249
+ whereDocument?: WhereDocument;
1250
+ include?: Include[];
1251
+ }): Promise<QueryResult<TMeta>> {
1252
+ if (!args.queryEmbeddings) {
1253
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
1254
+ }
1255
+ return super.query(args);
1256
+ }
1257
+
1258
+ public override async search(
1259
+ searches: SearchLike | SearchLike[],
1260
+ options?: { readLevel?: ReadLevel },
1261
+ ): Promise<SearchResult> {
1262
+ const items = Array.isArray(searches) ? searches : [searches];
1263
+ for (const search of items) {
1264
+ const payload = toSearch(search).toPayload();
1265
+ if (this.hasStringKnnQuery(payload.rank)) {
1266
+ throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
1267
+ }
1268
+ }
1269
+ return super.search(searches, options);
1270
+ }
1271
+
1272
+ public override async modify(_args: {
1273
+ name?: string;
1274
+ metadata?: CollectionMetadata;
1275
+ configuration?: UpdateCollectionConfiguration;
1276
+ }): Promise<void> {
1277
+ throw new ChromaValueError(`modify() ${HANDLE_NOT_SUPPORTED_ERROR}`);
1278
+ }
1279
+
1280
+ public override async fork(_args: { name: string }): Promise<Collection> {
1281
+ throw new ChromaValueError(`fork() ${HANDLE_NOT_SUPPORTED_ERROR}`);
1282
+ }
1283
+
1284
+ private hasStringKnnQuery(obj: unknown): boolean {
1285
+ if (!obj || typeof obj !== "object") return false;
1286
+ if (Array.isArray(obj)) {
1287
+ return obj.some((item) => this.hasStringKnnQuery(item));
1288
+ }
1289
+ const record = obj as Record<string, unknown>;
1290
+ if ("$knn" in record && isPlainObject(record.$knn)) {
1291
+ const knn = record.$knn as Record<string, unknown>;
1292
+ if (typeof knn.query === "string") return true;
1293
+ }
1294
+ return Object.values(record).some((value) =>
1295
+ this.hasStringKnnQuery(value),
1296
+ );
1297
+ }
1298
+ }
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  // Apply Deno compatibility patch
7
7
  import "./deno";
8
8
 
9
- export { Collection } from "./collection";
9
+ export { Collection, CollectionHandle } from "./collection";
10
10
  export { withChroma } from "./next";
11
11
  export * from "./types";
12
12
  export * from "./admin-client";