chromadb 3.3.3 → 3.4.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/README.md +1 -1
- package/dist/chromadb.d.ts +222 -1
- package/dist/chromadb.legacy-esm.js +117 -0
- package/dist/chromadb.mjs +117 -0
- package/dist/chromadb.mjs.map +1 -1
- package/dist/cjs/chromadb.cjs +118 -0
- package/dist/cjs/chromadb.cjs.map +1 -1
- package/dist/cjs/chromadb.d.cts +222 -1
- package/package.json +1 -1
- package/src/api/sdk.gen.ts +18 -1
- package/src/api/types.gen.ts +56 -0
- package/src/chroma-client.ts +28 -1
- package/src/collection.ts +155 -0
- package/src/index.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
## chromadb
|
|
2
2
|
|
|
3
|
-
Chroma is the open-source
|
|
3
|
+
Chroma is the open-source data infrastructure for AI. Chroma makes it easy to build LLM apps by making knowledge, facts, and skills pluggable for LLMs.
|
|
4
4
|
|
|
5
5
|
This package gives you a JS/TS interface to talk to a backend Chroma DB over REST.
|
|
6
6
|
|
package/dist/chromadb.d.ts
CHANGED
|
@@ -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 };
|
|
@@ -508,6 +508,22 @@ var CollectionService = class {
|
|
|
508
508
|
}
|
|
509
509
|
});
|
|
510
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* Get fork count
|
|
513
|
+
* Returns the number of forks for a collection.
|
|
514
|
+
*/
|
|
515
|
+
static forkCount(options) {
|
|
516
|
+
return (options.client ?? client).get({
|
|
517
|
+
security: [
|
|
518
|
+
{
|
|
519
|
+
name: "x-chroma-token",
|
|
520
|
+
type: "apiKey"
|
|
521
|
+
}
|
|
522
|
+
],
|
|
523
|
+
url: "/api/v2/tenants/{tenant}/databases/{database}/collections/{collection_id}/fork_count",
|
|
524
|
+
...options
|
|
525
|
+
});
|
|
526
|
+
}
|
|
511
527
|
/**
|
|
512
528
|
* Get number of collections
|
|
513
529
|
* Returns the total number of collections in a database.
|
|
@@ -4420,6 +4436,13 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
4420
4436
|
configuration: data.configuration_json
|
|
4421
4437
|
});
|
|
4422
4438
|
}
|
|
4439
|
+
async forkCount() {
|
|
4440
|
+
const { data } = await CollectionService.forkCount({
|
|
4441
|
+
client: this.apiClient,
|
|
4442
|
+
path: await this.path()
|
|
4443
|
+
});
|
|
4444
|
+
return data.count;
|
|
4445
|
+
}
|
|
4423
4446
|
async update({
|
|
4424
4447
|
ids,
|
|
4425
4448
|
embeddings,
|
|
@@ -4506,6 +4529,75 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
4506
4529
|
return data;
|
|
4507
4530
|
}
|
|
4508
4531
|
};
|
|
4532
|
+
var HANDLE_EMBEDDING_ERROR = "This operation requires an embedding function, which is not available on a collection obtained via client.collection(id). Provide pre-computed embeddings directly, or use client.getCollection() to get a full collection with embedding support.";
|
|
4533
|
+
var HANDLE_NOT_SUPPORTED_ERROR = "is not supported on a collection obtained via client.collection(id). Use client.getCollection() to get a full collection instance.";
|
|
4534
|
+
var CollectionHandle = class extends CollectionImpl {
|
|
4535
|
+
constructor({ chromaClient, apiClient, id, tenant, database }) {
|
|
4536
|
+
super({
|
|
4537
|
+
chromaClient,
|
|
4538
|
+
apiClient,
|
|
4539
|
+
id,
|
|
4540
|
+
tenant,
|
|
4541
|
+
database,
|
|
4542
|
+
name: "",
|
|
4543
|
+
configuration: {}
|
|
4544
|
+
});
|
|
4545
|
+
}
|
|
4546
|
+
async add(args) {
|
|
4547
|
+
if (!args.embeddings) {
|
|
4548
|
+
throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
|
|
4549
|
+
}
|
|
4550
|
+
return super.add(args);
|
|
4551
|
+
}
|
|
4552
|
+
async update(args) {
|
|
4553
|
+
if (!args.embeddings && args.documents) {
|
|
4554
|
+
throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
|
|
4555
|
+
}
|
|
4556
|
+
return super.update(args);
|
|
4557
|
+
}
|
|
4558
|
+
async upsert(args) {
|
|
4559
|
+
if (!args.embeddings) {
|
|
4560
|
+
throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
|
|
4561
|
+
}
|
|
4562
|
+
return super.upsert(args);
|
|
4563
|
+
}
|
|
4564
|
+
async query(args) {
|
|
4565
|
+
if (!args.queryEmbeddings) {
|
|
4566
|
+
throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
|
|
4567
|
+
}
|
|
4568
|
+
return super.query(args);
|
|
4569
|
+
}
|
|
4570
|
+
async search(searches, options) {
|
|
4571
|
+
const items = Array.isArray(searches) ? searches : [searches];
|
|
4572
|
+
for (const search of items) {
|
|
4573
|
+
const payload = toSearch(search).toPayload();
|
|
4574
|
+
if (this.hasStringKnnQuery(payload.rank)) {
|
|
4575
|
+
throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
|
|
4576
|
+
}
|
|
4577
|
+
}
|
|
4578
|
+
return super.search(searches, options);
|
|
4579
|
+
}
|
|
4580
|
+
async modify(_args) {
|
|
4581
|
+
throw new ChromaValueError(`modify() ${HANDLE_NOT_SUPPORTED_ERROR}`);
|
|
4582
|
+
}
|
|
4583
|
+
async fork(_args) {
|
|
4584
|
+
throw new ChromaValueError(`fork() ${HANDLE_NOT_SUPPORTED_ERROR}`);
|
|
4585
|
+
}
|
|
4586
|
+
hasStringKnnQuery(obj) {
|
|
4587
|
+
if (!obj || typeof obj !== "object") return false;
|
|
4588
|
+
if (Array.isArray(obj)) {
|
|
4589
|
+
return obj.some((item) => this.hasStringKnnQuery(item));
|
|
4590
|
+
}
|
|
4591
|
+
const record = obj;
|
|
4592
|
+
if ("$knn" in record && isPlainObject(record.$knn)) {
|
|
4593
|
+
const knn = record.$knn;
|
|
4594
|
+
if (typeof knn.query === "string") return true;
|
|
4595
|
+
}
|
|
4596
|
+
return Object.values(record).some(
|
|
4597
|
+
(value) => this.hasStringKnnQuery(value)
|
|
4598
|
+
);
|
|
4599
|
+
}
|
|
4600
|
+
};
|
|
4509
4601
|
|
|
4510
4602
|
// src/next.ts
|
|
4511
4603
|
function withChroma(userNextConfig = {}) {
|
|
@@ -5092,6 +5184,30 @@ var ChromaClient = class {
|
|
|
5092
5184
|
schema: serverSchema
|
|
5093
5185
|
});
|
|
5094
5186
|
}
|
|
5187
|
+
/**
|
|
5188
|
+
* Returns a lightweight collection handle for the given collection ID.
|
|
5189
|
+
* The handle supports operations that don't require an embedding function
|
|
5190
|
+
* or schema (e.g., add with pre-computed embeddings, get, delete, count, search).
|
|
5191
|
+
* Operations that require an embedding function will throw a clear error
|
|
5192
|
+
* directing you to use {@link getCollection} instead.
|
|
5193
|
+
* @param id - The collection ID
|
|
5194
|
+
* @returns A Collection handle for the given ID
|
|
5195
|
+
* @throws ChromaValueError if tenant or database are not set on the client
|
|
5196
|
+
*/
|
|
5197
|
+
collection(id) {
|
|
5198
|
+
if (!this._tenant || !this._database) {
|
|
5199
|
+
throw new ChromaValueError(
|
|
5200
|
+
"tenant and database must be set on the client before calling collection(). Provide them in the ChromaClient constructor or use getCollection() instead."
|
|
5201
|
+
);
|
|
5202
|
+
}
|
|
5203
|
+
return new CollectionHandle({
|
|
5204
|
+
chromaClient: this,
|
|
5205
|
+
apiClient: this.apiClient,
|
|
5206
|
+
id,
|
|
5207
|
+
tenant: this._tenant,
|
|
5208
|
+
database: this._database
|
|
5209
|
+
});
|
|
5210
|
+
}
|
|
5095
5211
|
/**
|
|
5096
5212
|
* Deletes a collection and all its data.
|
|
5097
5213
|
* @param options - Deletion options
|
|
@@ -5228,6 +5344,7 @@ export {
|
|
|
5228
5344
|
CloudClient,
|
|
5229
5345
|
Cmek,
|
|
5230
5346
|
CmekProvider,
|
|
5347
|
+
CollectionHandle,
|
|
5231
5348
|
DOCUMENT_KEY,
|
|
5232
5349
|
Div,
|
|
5233
5350
|
EMBEDDING_KEY,
|
package/dist/chromadb.mjs
CHANGED
|
@@ -508,6 +508,22 @@ var CollectionService = class {
|
|
|
508
508
|
}
|
|
509
509
|
});
|
|
510
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* Get fork count
|
|
513
|
+
* Returns the number of forks for a collection.
|
|
514
|
+
*/
|
|
515
|
+
static forkCount(options) {
|
|
516
|
+
return (options.client ?? client).get({
|
|
517
|
+
security: [
|
|
518
|
+
{
|
|
519
|
+
name: "x-chroma-token",
|
|
520
|
+
type: "apiKey"
|
|
521
|
+
}
|
|
522
|
+
],
|
|
523
|
+
url: "/api/v2/tenants/{tenant}/databases/{database}/collections/{collection_id}/fork_count",
|
|
524
|
+
...options
|
|
525
|
+
});
|
|
526
|
+
}
|
|
511
527
|
/**
|
|
512
528
|
* Get number of collections
|
|
513
529
|
* Returns the total number of collections in a database.
|
|
@@ -4420,6 +4436,13 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
4420
4436
|
configuration: data.configuration_json
|
|
4421
4437
|
});
|
|
4422
4438
|
}
|
|
4439
|
+
async forkCount() {
|
|
4440
|
+
const { data } = await CollectionService.forkCount({
|
|
4441
|
+
client: this.apiClient,
|
|
4442
|
+
path: await this.path()
|
|
4443
|
+
});
|
|
4444
|
+
return data.count;
|
|
4445
|
+
}
|
|
4423
4446
|
async update({
|
|
4424
4447
|
ids,
|
|
4425
4448
|
embeddings,
|
|
@@ -4506,6 +4529,75 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
4506
4529
|
return data;
|
|
4507
4530
|
}
|
|
4508
4531
|
};
|
|
4532
|
+
var HANDLE_EMBEDDING_ERROR = "This operation requires an embedding function, which is not available on a collection obtained via client.collection(id). Provide pre-computed embeddings directly, or use client.getCollection() to get a full collection with embedding support.";
|
|
4533
|
+
var HANDLE_NOT_SUPPORTED_ERROR = "is not supported on a collection obtained via client.collection(id). Use client.getCollection() to get a full collection instance.";
|
|
4534
|
+
var CollectionHandle = class extends CollectionImpl {
|
|
4535
|
+
constructor({ chromaClient, apiClient, id, tenant, database }) {
|
|
4536
|
+
super({
|
|
4537
|
+
chromaClient,
|
|
4538
|
+
apiClient,
|
|
4539
|
+
id,
|
|
4540
|
+
tenant,
|
|
4541
|
+
database,
|
|
4542
|
+
name: "",
|
|
4543
|
+
configuration: {}
|
|
4544
|
+
});
|
|
4545
|
+
}
|
|
4546
|
+
async add(args) {
|
|
4547
|
+
if (!args.embeddings) {
|
|
4548
|
+
throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
|
|
4549
|
+
}
|
|
4550
|
+
return super.add(args);
|
|
4551
|
+
}
|
|
4552
|
+
async update(args) {
|
|
4553
|
+
if (!args.embeddings && args.documents) {
|
|
4554
|
+
throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
|
|
4555
|
+
}
|
|
4556
|
+
return super.update(args);
|
|
4557
|
+
}
|
|
4558
|
+
async upsert(args) {
|
|
4559
|
+
if (!args.embeddings) {
|
|
4560
|
+
throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
|
|
4561
|
+
}
|
|
4562
|
+
return super.upsert(args);
|
|
4563
|
+
}
|
|
4564
|
+
async query(args) {
|
|
4565
|
+
if (!args.queryEmbeddings) {
|
|
4566
|
+
throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
|
|
4567
|
+
}
|
|
4568
|
+
return super.query(args);
|
|
4569
|
+
}
|
|
4570
|
+
async search(searches, options) {
|
|
4571
|
+
const items = Array.isArray(searches) ? searches : [searches];
|
|
4572
|
+
for (const search of items) {
|
|
4573
|
+
const payload = toSearch(search).toPayload();
|
|
4574
|
+
if (this.hasStringKnnQuery(payload.rank)) {
|
|
4575
|
+
throw new ChromaValueError(HANDLE_EMBEDDING_ERROR);
|
|
4576
|
+
}
|
|
4577
|
+
}
|
|
4578
|
+
return super.search(searches, options);
|
|
4579
|
+
}
|
|
4580
|
+
async modify(_args) {
|
|
4581
|
+
throw new ChromaValueError(`modify() ${HANDLE_NOT_SUPPORTED_ERROR}`);
|
|
4582
|
+
}
|
|
4583
|
+
async fork(_args) {
|
|
4584
|
+
throw new ChromaValueError(`fork() ${HANDLE_NOT_SUPPORTED_ERROR}`);
|
|
4585
|
+
}
|
|
4586
|
+
hasStringKnnQuery(obj) {
|
|
4587
|
+
if (!obj || typeof obj !== "object") return false;
|
|
4588
|
+
if (Array.isArray(obj)) {
|
|
4589
|
+
return obj.some((item) => this.hasStringKnnQuery(item));
|
|
4590
|
+
}
|
|
4591
|
+
const record = obj;
|
|
4592
|
+
if ("$knn" in record && isPlainObject(record.$knn)) {
|
|
4593
|
+
const knn = record.$knn;
|
|
4594
|
+
if (typeof knn.query === "string") return true;
|
|
4595
|
+
}
|
|
4596
|
+
return Object.values(record).some(
|
|
4597
|
+
(value) => this.hasStringKnnQuery(value)
|
|
4598
|
+
);
|
|
4599
|
+
}
|
|
4600
|
+
};
|
|
4509
4601
|
|
|
4510
4602
|
// src/next.ts
|
|
4511
4603
|
function withChroma(userNextConfig = {}) {
|
|
@@ -5092,6 +5184,30 @@ var ChromaClient = class {
|
|
|
5092
5184
|
schema: serverSchema
|
|
5093
5185
|
});
|
|
5094
5186
|
}
|
|
5187
|
+
/**
|
|
5188
|
+
* Returns a lightweight collection handle for the given collection ID.
|
|
5189
|
+
* The handle supports operations that don't require an embedding function
|
|
5190
|
+
* or schema (e.g., add with pre-computed embeddings, get, delete, count, search).
|
|
5191
|
+
* Operations that require an embedding function will throw a clear error
|
|
5192
|
+
* directing you to use {@link getCollection} instead.
|
|
5193
|
+
* @param id - The collection ID
|
|
5194
|
+
* @returns A Collection handle for the given ID
|
|
5195
|
+
* @throws ChromaValueError if tenant or database are not set on the client
|
|
5196
|
+
*/
|
|
5197
|
+
collection(id) {
|
|
5198
|
+
if (!this._tenant || !this._database) {
|
|
5199
|
+
throw new ChromaValueError(
|
|
5200
|
+
"tenant and database must be set on the client before calling collection(). Provide them in the ChromaClient constructor or use getCollection() instead."
|
|
5201
|
+
);
|
|
5202
|
+
}
|
|
5203
|
+
return new CollectionHandle({
|
|
5204
|
+
chromaClient: this,
|
|
5205
|
+
apiClient: this.apiClient,
|
|
5206
|
+
id,
|
|
5207
|
+
tenant: this._tenant,
|
|
5208
|
+
database: this._database
|
|
5209
|
+
});
|
|
5210
|
+
}
|
|
5095
5211
|
/**
|
|
5096
5212
|
* Deletes a collection and all its data.
|
|
5097
5213
|
* @param options - Deletion options
|
|
@@ -5228,6 +5344,7 @@ export {
|
|
|
5228
5344
|
CloudClient,
|
|
5229
5345
|
Cmek,
|
|
5230
5346
|
CmekProvider,
|
|
5347
|
+
CollectionHandle,
|
|
5231
5348
|
DOCUMENT_KEY,
|
|
5232
5349
|
Div,
|
|
5233
5350
|
EMBEDDING_KEY,
|