chromadb 3.3.2 → 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 +224 -3
- package/dist/chromadb.legacy-esm.js +128 -67
- package/dist/chromadb.mjs +128 -67
- package/dist/chromadb.mjs.map +1 -1
- package/dist/cjs/chromadb.cjs +129 -67
- package/dist/cjs/chromadb.cjs.map +1 -1
- package/dist/cjs/chromadb.d.cts +224 -3
- 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 -6
- package/src/collection-configuration.ts +0 -1
- package/src/collection.ts +162 -6
- package/src/embedding-function.ts +11 -68
- package/src/index.ts +1 -1
- package/src/schema.ts +0 -2
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
|
};
|
|
@@ -757,7 +759,6 @@ declare const registerSparseEmbeddingFunction: (name: string, fn: SparseEmbeddin
|
|
|
757
759
|
* @returns EmbeddingFunction instance or undefined if it cannot be constructed
|
|
758
760
|
*/
|
|
759
761
|
declare const getEmbeddingFunction: (args: {
|
|
760
|
-
collectionName: string;
|
|
761
762
|
client: ChromaClient;
|
|
762
763
|
efConfig?: EmbeddingFunctionConfiguration;
|
|
763
764
|
}) => Promise<EmbeddingFunction | undefined>;
|
|
@@ -765,7 +766,7 @@ declare const getEmbeddingFunction: (args: {
|
|
|
765
766
|
* Retrieves and instantiates a sparse embedding function from configuration.
|
|
766
767
|
* @returns SparseEmbeddingFunction instance or undefined if it cannot be constructed
|
|
767
768
|
*/
|
|
768
|
-
declare const getSparseEmbeddingFunction: (
|
|
769
|
+
declare const getSparseEmbeddingFunction: (client: ChromaClient, efConfig?: EmbeddingFunctionConfiguration) => Promise<SparseEmbeddingFunction | undefined>;
|
|
769
770
|
/**
|
|
770
771
|
* Serializes an embedding function to configuration format.
|
|
771
772
|
* @param embeddingFunction - User provided embedding function
|
|
@@ -1516,6 +1517,17 @@ declare class ChromaClient {
|
|
|
1516
1517
|
embeddingFunction?: EmbeddingFunction | null;
|
|
1517
1518
|
schema?: Schema;
|
|
1518
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;
|
|
1519
1531
|
/**
|
|
1520
1532
|
* Deletes a collection and all its data.
|
|
1521
1533
|
* @param options - Deletion options
|
|
@@ -1673,6 +1685,11 @@ interface Collection {
|
|
|
1673
1685
|
fork({ name }: {
|
|
1674
1686
|
name: string;
|
|
1675
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>;
|
|
1676
1693
|
/**
|
|
1677
1694
|
* Updates existing records in the collection.
|
|
1678
1695
|
* @param args - Record data to update
|
|
@@ -1722,6 +1739,7 @@ interface Collection {
|
|
|
1722
1739
|
/**
|
|
1723
1740
|
* Performs hybrid search on the collection using expression builders.
|
|
1724
1741
|
* @param searches - Single search payload or array of payloads
|
|
1742
|
+
* @param options
|
|
1725
1743
|
* @returns Promise resolving to column-major search results
|
|
1726
1744
|
*/
|
|
1727
1745
|
search(searches: SearchLike | SearchLike[], options?: {
|
|
@@ -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.
|
|
@@ -1516,7 +1532,9 @@ var pythonEmbeddingFunctions = {
|
|
|
1516
1532
|
default: "default-embed",
|
|
1517
1533
|
together_ai: "together-ai",
|
|
1518
1534
|
sentence_transformer: "sentence-transformer",
|
|
1535
|
+
google_gemini: "google-gemini",
|
|
1519
1536
|
google_genai: "google-gemini"
|
|
1537
|
+
// Backward compatibility alias
|
|
1520
1538
|
};
|
|
1521
1539
|
var unsupportedEmbeddingFunctions = /* @__PURE__ */ new Set([
|
|
1522
1540
|
"amazon_bedrock",
|
|
@@ -1555,32 +1573,11 @@ var registerSparseEmbeddingFunction = (name, fn) => {
|
|
|
1555
1573
|
knownSparseEmbeddingFunctions.set(name, fn);
|
|
1556
1574
|
};
|
|
1557
1575
|
var getEmbeddingFunction = async (args) => {
|
|
1558
|
-
const {
|
|
1559
|
-
if (
|
|
1560
|
-
console.warn(
|
|
1561
|
-
`No embedding function configuration found for collection ${collectionName}. 'add' and 'query' will fail unless you provide them embeddings directly.`
|
|
1562
|
-
);
|
|
1563
|
-
return void 0;
|
|
1564
|
-
}
|
|
1565
|
-
if (efConfig.type === "legacy") {
|
|
1566
|
-
console.warn(
|
|
1567
|
-
`No embedding function configuration found for collection ${collectionName}. 'add' and 'query' will fail unless you provide them embeddings directly.`
|
|
1568
|
-
);
|
|
1569
|
-
return void 0;
|
|
1570
|
-
}
|
|
1571
|
-
if (efConfig.type === "unknown") {
|
|
1572
|
-
console.warn(
|
|
1573
|
-
`Unknown embedding function configuration for collection ${collectionName}. 'add' and 'query' will fail unless you provide them embeddings directly.`
|
|
1574
|
-
);
|
|
1575
|
-
return void 0;
|
|
1576
|
-
}
|
|
1577
|
-
if (efConfig.type !== "known") {
|
|
1576
|
+
const { client: client2, efConfig } = args;
|
|
1577
|
+
if (efConfig?.type !== "known") {
|
|
1578
1578
|
return void 0;
|
|
1579
1579
|
}
|
|
1580
1580
|
if (unsupportedEmbeddingFunctions.has(efConfig.name)) {
|
|
1581
|
-
console.warn(
|
|
1582
|
-
`Embedding function ${efConfig.name} is not supported in the JS/TS SDK. 'add' and 'query' will fail unless you provide them embeddings directly.`
|
|
1583
|
-
);
|
|
1584
1581
|
return void 0;
|
|
1585
1582
|
}
|
|
1586
1583
|
const packageName = pythonEmbeddingFunctions[efConfig.name] || efConfig.name;
|
|
@@ -1596,42 +1593,24 @@ var getEmbeddingFunction = async (args) => {
|
|
|
1596
1593
|
} catch (error) {
|
|
1597
1594
|
}
|
|
1598
1595
|
if (!embeddingFunction) {
|
|
1599
|
-
console.warn(
|
|
1600
|
-
`Collection ${collectionName} was created with the ${packageName} embedding function. However, the @chroma-core/${packageName} package is not installed. 'add' and 'query' will fail unless you provide them embeddings directly, or install the @chroma-core/${packageName} package.`
|
|
1601
|
-
);
|
|
1602
1596
|
return void 0;
|
|
1603
1597
|
}
|
|
1604
1598
|
}
|
|
1605
|
-
|
|
1599
|
+
const constructorConfig = efConfig.config ?? {};
|
|
1606
1600
|
try {
|
|
1607
1601
|
if (embeddingFunction.buildFromConfig) {
|
|
1608
1602
|
return embeddingFunction.buildFromConfig(constructorConfig, client2);
|
|
1609
1603
|
}
|
|
1610
|
-
console.warn(
|
|
1611
|
-
`Embedding function ${packageName} does not define a 'buildFromConfig' function. 'add' and 'query' will fail unless you provide them embeddings directly.`
|
|
1612
|
-
);
|
|
1613
1604
|
return void 0;
|
|
1614
1605
|
} catch (e) {
|
|
1615
|
-
console.warn(
|
|
1616
|
-
`Embedding function ${packageName} failed to build with config: ${constructorConfig}. 'add' and 'query' will fail unless you provide them embeddings directly. Error: ${e}`
|
|
1617
|
-
);
|
|
1618
1606
|
return void 0;
|
|
1619
1607
|
}
|
|
1620
1608
|
};
|
|
1621
|
-
var getSparseEmbeddingFunction = async (
|
|
1622
|
-
if (
|
|
1623
|
-
return void 0;
|
|
1624
|
-
}
|
|
1625
|
-
if (efConfig.type === "legacy") {
|
|
1626
|
-
return void 0;
|
|
1627
|
-
}
|
|
1628
|
-
if (efConfig.type !== "known") {
|
|
1609
|
+
var getSparseEmbeddingFunction = async (client2, efConfig) => {
|
|
1610
|
+
if (efConfig?.type !== "known") {
|
|
1629
1611
|
return void 0;
|
|
1630
1612
|
}
|
|
1631
1613
|
if (unsupportedSparseEmbeddingFunctions.has(efConfig.name)) {
|
|
1632
|
-
console.warn(
|
|
1633
|
-
"Embedding function ${efConfig.name} is not supported in the JS/TS SDK. 'add' and 'query' will fail unless you provide them embeddings directly."
|
|
1634
|
-
);
|
|
1635
1614
|
return void 0;
|
|
1636
1615
|
}
|
|
1637
1616
|
const packageName = pythonSparseEmbeddingFunctions[efConfig.name] || efConfig.name;
|
|
@@ -1644,25 +1623,16 @@ var getSparseEmbeddingFunction = async (collectionName, client2, efConfig) => {
|
|
|
1644
1623
|
} catch (error) {
|
|
1645
1624
|
}
|
|
1646
1625
|
if (!sparseEmbeddingFunction) {
|
|
1647
|
-
console.warn(
|
|
1648
|
-
`Collection ${collectionName} was created with the ${packageName} sparse embedding function. However, the @chroma-core/${packageName} package is not installed.`
|
|
1649
|
-
);
|
|
1650
1626
|
return void 0;
|
|
1651
1627
|
}
|
|
1652
1628
|
}
|
|
1653
|
-
|
|
1629
|
+
const constructorConfig = efConfig.config ?? {};
|
|
1654
1630
|
try {
|
|
1655
1631
|
if (sparseEmbeddingFunction.buildFromConfig) {
|
|
1656
1632
|
return sparseEmbeddingFunction.buildFromConfig(constructorConfig, client2);
|
|
1657
1633
|
}
|
|
1658
|
-
console.warn(
|
|
1659
|
-
`Sparse embedding function ${packageName} does not define a 'buildFromConfig' function.`
|
|
1660
|
-
);
|
|
1661
1634
|
return void 0;
|
|
1662
1635
|
} catch (e) {
|
|
1663
|
-
console.warn(
|
|
1664
|
-
`Sparse embedding function ${packageName} failed to build with config: ${constructorConfig}. Error: ${e}`
|
|
1665
|
-
);
|
|
1666
1636
|
return void 0;
|
|
1667
1637
|
}
|
|
1668
1638
|
};
|
|
@@ -1788,7 +1758,6 @@ var processUpdateCollectionConfig = async ({
|
|
|
1788
1758
|
);
|
|
1789
1759
|
}
|
|
1790
1760
|
const embeddingFunction = currentEmbeddingFunction || await getEmbeddingFunction({
|
|
1791
|
-
collectionName,
|
|
1792
1761
|
client: client2,
|
|
1793
1762
|
efConfig: currentConfiguration.embeddingFunction ?? void 0
|
|
1794
1763
|
});
|
|
@@ -3886,7 +3855,6 @@ var Schema = class _Schema {
|
|
|
3886
3855
|
spann: json.spann ? cloneObject(json.spann) : null
|
|
3887
3856
|
});
|
|
3888
3857
|
config.embeddingFunction = await getEmbeddingFunction({
|
|
3889
|
-
collectionName: "schema deserialization",
|
|
3890
3858
|
client: client2,
|
|
3891
3859
|
efConfig: json.embedding_function
|
|
3892
3860
|
});
|
|
@@ -3901,7 +3869,6 @@ var Schema = class _Schema {
|
|
|
3901
3869
|
bm25: typeof json.bm25 === "boolean" ? json.bm25 : null
|
|
3902
3870
|
});
|
|
3903
3871
|
const embeddingFunction = await getSparseEmbeddingFunction(
|
|
3904
|
-
"schema deserialization",
|
|
3905
3872
|
client2,
|
|
3906
3873
|
json.embedding_function
|
|
3907
3874
|
) ?? config.embeddingFunction ?? void 0;
|
|
@@ -3987,7 +3954,7 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
3987
3954
|
const embeddingFunction = this._embeddingFunction ?? this.getSchemaEmbeddingFunction();
|
|
3988
3955
|
if (!embeddingFunction) {
|
|
3989
3956
|
throw new ChromaValueError(
|
|
3990
|
-
|
|
3957
|
+
`No embedding function found for collection '${this._name}'. You can either provide embeddings directly, or ensure the appropriate embedding function package (e.g. @chroma-core/default-embed) is installed.`
|
|
3991
3958
|
);
|
|
3992
3959
|
}
|
|
3993
3960
|
if (isQuery && embeddingFunction.generateForQueries) {
|
|
@@ -4048,10 +4015,8 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
4048
4015
|
}
|
|
4049
4016
|
if (index < documentsList.length) {
|
|
4050
4017
|
const doc = documentsList[index];
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
positions.push(index);
|
|
4054
|
-
}
|
|
4018
|
+
inputs.push(doc);
|
|
4019
|
+
positions.push(index);
|
|
4055
4020
|
}
|
|
4056
4021
|
});
|
|
4057
4022
|
if (inputs.length === 0) {
|
|
@@ -4471,6 +4436,13 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
4471
4436
|
configuration: data.configuration_json
|
|
4472
4437
|
});
|
|
4473
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
|
+
}
|
|
4474
4446
|
async update({
|
|
4475
4447
|
ids,
|
|
4476
4448
|
embeddings,
|
|
@@ -4557,6 +4529,75 @@ var CollectionImpl = class _CollectionImpl {
|
|
|
4557
4529
|
return data;
|
|
4558
4530
|
}
|
|
4559
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
|
+
};
|
|
4560
4601
|
|
|
4561
4602
|
// src/next.ts
|
|
4562
4603
|
function withChroma(userNextConfig = {}) {
|
|
@@ -4918,7 +4959,6 @@ var ChromaClient = class {
|
|
|
4918
4959
|
);
|
|
4919
4960
|
const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
|
|
4920
4961
|
const resolvedEmbeddingFunction = await getEmbeddingFunction({
|
|
4921
|
-
collectionName: collection.name,
|
|
4922
4962
|
client: this,
|
|
4923
4963
|
efConfig: collection.configuration_json.embedding_function ?? void 0
|
|
4924
4964
|
}) ?? schemaEmbeddingFunction;
|
|
@@ -4988,7 +5028,6 @@ var ChromaClient = class {
|
|
|
4988
5028
|
);
|
|
4989
5029
|
const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(serverSchema);
|
|
4990
5030
|
const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
|
|
4991
|
-
collectionName: data.name,
|
|
4992
5031
|
client: this,
|
|
4993
5032
|
efConfig: data.configuration_json.embedding_function ?? void 0
|
|
4994
5033
|
}) ?? schemaEmbeddingFunction;
|
|
@@ -5024,7 +5063,6 @@ var ChromaClient = class {
|
|
|
5024
5063
|
const schema = await Schema.deserializeFromJSON(data.schema ?? null, this);
|
|
5025
5064
|
const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
|
|
5026
5065
|
const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
|
|
5027
|
-
collectionName: data.name,
|
|
5028
5066
|
client: this,
|
|
5029
5067
|
efConfig: data.configuration_json.embedding_function ?? void 0
|
|
5030
5068
|
}) ?? schemaEmbeddingFunction;
|
|
@@ -5055,7 +5093,6 @@ var ChromaClient = class {
|
|
|
5055
5093
|
const schema = await Schema.deserializeFromJSON(data.schema ?? null, this);
|
|
5056
5094
|
const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(schema);
|
|
5057
5095
|
const resolvedEmbeddingFunction = await getEmbeddingFunction({
|
|
5058
|
-
collectionName: data.name,
|
|
5059
5096
|
efConfig: data.configuration_json.embedding_function ?? void 0,
|
|
5060
5097
|
client: this
|
|
5061
5098
|
}) ?? schemaEmbeddingFunction;
|
|
@@ -5131,7 +5168,6 @@ var ChromaClient = class {
|
|
|
5131
5168
|
);
|
|
5132
5169
|
const schemaEmbeddingFunction = resolveSchemaEmbeddingFunction(serverSchema);
|
|
5133
5170
|
const resolvedEmbeddingFunction = embeddingFunction ?? await getEmbeddingFunction({
|
|
5134
|
-
collectionName: name,
|
|
5135
5171
|
efConfig: data.configuration_json.embedding_function ?? void 0,
|
|
5136
5172
|
client: this
|
|
5137
5173
|
}) ?? schemaEmbeddingFunction;
|
|
@@ -5148,6 +5184,30 @@ var ChromaClient = class {
|
|
|
5148
5184
|
schema: serverSchema
|
|
5149
5185
|
});
|
|
5150
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
|
+
}
|
|
5151
5211
|
/**
|
|
5152
5212
|
* Deletes a collection and all its data.
|
|
5153
5213
|
* @param options - Deletion options
|
|
@@ -5284,6 +5344,7 @@ export {
|
|
|
5284
5344
|
CloudClient,
|
|
5285
5345
|
Cmek,
|
|
5286
5346
|
CmekProvider,
|
|
5347
|
+
CollectionHandle,
|
|
5287
5348
|
DOCUMENT_KEY,
|
|
5288
5349
|
Div,
|
|
5289
5350
|
EMBEDDING_KEY,
|