Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Export Collection type directly #3178

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions clients/js/src/ChromaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export class ChromaClient {
/**
* Lists all collections.
*
* @returns {Promise<CollectionType[]>} A promise that resolves to a list of collection names.
itaismith marked this conversation as resolved.
Show resolved Hide resolved
* @returns {Promise<string[]>} A promise that resolves to a list of collection names.
* @param {PositiveInteger} [params.limit] - Optional limit on the number of items to get.
* @param {PositiveInteger} [params.offset] - Optional offset on the items to get.
* @throws {Error} If there is an issue listing the collections.
Expand All @@ -304,16 +304,17 @@ export class ChromaClient {
* ```
*/
async listCollections({ limit, offset }: ListCollectionsParams = {}): Promise<
CollectionParams[]
string[]
> {
await this.init();
return (await this.api.listCollections(
const collections = (await this.api.listCollections(
this.tenant,
this.database,
limit,
offset,
this.api.options,
)) as CollectionParams[];
)) as Collection[];
return collections.map((collection: Collection) => collection.name);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion clients/js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { ChromaClient } from "./ChromaClient";
export { AdminClient } from "./AdminClient";
export { CloudClient } from "./CloudClient";
export { Collection } from "./Collection";
export type { IEmbeddingFunction } from "./embeddings/IEmbeddingFunction";
export { OpenAIEmbeddingFunction } from "./embeddings/OpenAIEmbeddingFunction";
export { CohereEmbeddingFunction } from "./embeddings/CohereEmbeddingFunction";
Expand All @@ -14,7 +15,6 @@ export { OllamaEmbeddingFunction } from "./embeddings/OllamaEmbeddingFunction";
export type {
IncludeEnum,
GetParams,
CollectionType,
CollectionMetadata,
Embedding,
Embeddings,
Expand Down
7 changes: 0 additions & 7 deletions clients/js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ export type WhereDocument = {
| WhereDocument[];
};

export type CollectionType = {
name: string;
id: string;
metadata: Metadata | null;
configuration_json: any;
};

export type MultiGetResponse = {
ids: IDs;
embeddings: Embeddings | null;
Expand Down
46 changes: 4 additions & 42 deletions clients/js/test/collection.client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import {
test,
beforeEach,
describe,
afterAll,
beforeAll,
} from "@jest/globals";
import { DefaultEmbeddingFunction } from "../src/embeddings/DefaultEmbeddingFunction";
import { StartedTestContainer } from "testcontainers";
import { ChromaClient } from "../src/ChromaClient";
import { startChromaContainer } from "./startChromaContainer";
import { DefaultEmbeddingFunction } from "../src";
import { ChromaClient } from "../src";

describe("collection operations", () => {
// connects to the unauthenticated chroma instance started in
Expand Down Expand Up @@ -42,23 +38,7 @@ describe("collection operations", () => {

const [returnedCollection] = collections;

expect({
...returnedCollection,
configuration_json: undefined,
id: undefined,
}).toMatchInlineSnapshot(`
{
"configuration_json": undefined,
"database": "default_database",
"dimension": null,
"id": undefined,
"log_position": 0,
"metadata": null,
"name": "test",
"tenant": "default_tenant",
"version": 0,
}
`);
expect(returnedCollection).toEqual("test")

expect([{ name: "test2", metadata: null }]).not.toEqual(
expect.arrayContaining(collections),
Expand All @@ -79,25 +59,7 @@ describe("collection operations", () => {
const collections2 = await client.listCollections();
expect(collections2).toHaveLength(1);
const [returnedCollection2] = collections2;
expect({
...returnedCollection2,
configuration_json: undefined,
id: undefined,
}).toMatchInlineSnapshot(`
{
"configuration_json": undefined,
"database": "default_database",
"dimension": null,
"id": undefined,
"log_position": 0,
"metadata": {
"test": "test",
},
"name": "test2",
"tenant": "default_tenant",
"version": 0,
}
`);
expect(returnedCollection2).toEqual("test2");
});

test("it should get a collection", async () => {
Expand Down
Loading