Skip to content

Commit ecf735c

Browse files
authored
Revert "[ENH] Expose rawjson from schema in js client" (chroma-core#6464)
Reverts chroma-core#6460
1 parent 1bfd114 commit ecf735c

2 files changed

Lines changed: 0 additions & 149 deletions

File tree

clients/new-js/packages/chromadb/src/schema.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ export class Schema {
471471
defaults: ValueTypes;
472472
keys: Record<string, ValueTypes>;
473473
cmek: Cmek | null;
474-
private _rawJSON: Record<string, unknown> | null = null;
475474

476475
constructor() {
477476
this.defaults = new ValueTypes();
@@ -481,18 +480,6 @@ export class Schema {
481480
this.initializeKeys();
482481
}
483482

484-
/**
485-
* Returns the raw JSON schema as received from the server, or null if the
486-
* schema was constructed client-side rather than deserialized from a server
487-
* response.
488-
*/
489-
get rawJSON(): Record<string, unknown> | null {
490-
if (this._rawJSON === null) {
491-
return null;
492-
}
493-
return structuredClone(this._rawJSON);
494-
}
495-
496483
/**
497484
* Set the customer-managed encryption key for this collection.
498485
*
@@ -684,7 +671,6 @@ export class Schema {
684671

685672
const data = json as JsonDict;
686673
const instance = Object.create(Schema.prototype) as Schema;
687-
instance._rawJSON = structuredClone(data) as Record<string, unknown>;
688674
instance.defaults = await Schema.deserializeValueTypes(
689675
(data.defaults ?? {}) as Record<string, any>,
690676
client,

clients/new-js/packages/chromadb/test/schema.test.ts

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,139 +1967,4 @@ describe("Schema", () => {
19671967
const deserialized = await Schema.deserializeFromJSON(json, client);
19681968
expect(deserialized?.cmek).toBeNull();
19691969
});
1970-
1971-
it("rawJSON is null for client-constructed schemas", () => {
1972-
const schema = new Schema();
1973-
expect(schema.rawJSON).toBeNull();
1974-
});
1975-
1976-
it("rawJSON is populated after deserializeFromJSON", async () => {
1977-
const schema = new Schema();
1978-
const json = schema.serializeToJSON();
1979-
1980-
const deserialized = await Schema.deserializeFromJSON(json, client);
1981-
expect(deserialized).toBeDefined();
1982-
expect(deserialized!.rawJSON).not.toBeNull();
1983-
expect(deserialized!.rawJSON).toHaveProperty("defaults");
1984-
expect(deserialized!.rawJSON).toHaveProperty("keys");
1985-
});
1986-
1987-
it("rawJSON matches the original JSON passed to deserializeFromJSON", async () => {
1988-
const schema = new Schema();
1989-
const mockEf = new MockEmbedding("raw_json_test");
1990-
schema.createIndex(
1991-
new VectorIndexConfig({
1992-
embeddingFunction: mockEf,
1993-
space: "cosine",
1994-
hnsw: { ef_construction: 200, max_neighbors: 32 },
1995-
}),
1996-
);
1997-
schema.createIndex(
1998-
new SparseVectorIndexConfig({
1999-
embeddingFunction: new MockSparseEmbedding("raw_sparse"),
2000-
sourceKey: "text_field",
2001-
}),
2002-
"sparse_key",
2003-
);
2004-
schema.deleteIndex(new StringInvertedIndexConfig(), "no_index_field");
2005-
2006-
const json = schema.serializeToJSON();
2007-
const deserialized = await Schema.deserializeFromJSON(json, client);
2008-
2009-
expect(deserialized!.rawJSON).toEqual(json);
2010-
});
2011-
2012-
it("rawJSON returns a deep copy (mutations do not affect stored value)", async () => {
2013-
const schema = new Schema();
2014-
const json = schema.serializeToJSON();
2015-
2016-
const deserialized = await Schema.deserializeFromJSON(json, client);
2017-
const raw1 = deserialized!.rawJSON!;
2018-
const raw2 = deserialized!.rawJSON!;
2019-
2020-
// Should be equal but not the same reference
2021-
expect(raw1).toEqual(raw2);
2022-
expect(raw1).not.toBe(raw2);
2023-
2024-
// Mutating the returned copy should not affect the stored value
2025-
(raw1 as any).defaults = "mutated";
2026-
expect(deserialized!.rawJSON!.defaults).not.toBe("mutated");
2027-
});
2028-
2029-
it("rawJSON is not affected by subsequent schema modifications", async () => {
2030-
const schema = new Schema();
2031-
const json = schema.serializeToJSON();
2032-
2033-
const deserialized = await Schema.deserializeFromJSON(json, client);
2034-
const rawBefore = deserialized!.rawJSON;
2035-
2036-
// The original json input should be preserved even though the
2037-
// deserialized schema object could theoretically be mutated
2038-
expect(rawBefore).toEqual(json);
2039-
});
2040-
2041-
it("rawJSON preserves extra fields from server response", async () => {
2042-
// Simulate a server response that contains fields the client doesn't know about
2043-
const serverJson = {
2044-
defaults: {
2045-
string: {
2046-
fts_index: { enabled: false, config: {} },
2047-
string_inverted_index: { enabled: true, config: {} },
2048-
},
2049-
},
2050-
keys: {},
2051-
some_future_field: "unexpected_value",
2052-
source_attached_function_id: "func-123",
2053-
};
2054-
2055-
const deserialized = await Schema.deserializeFromJSON(serverJson, client);
2056-
expect(deserialized).toBeDefined();
2057-
2058-
// rawJSON should contain the extra fields the client doesn't parse
2059-
const raw = deserialized!.rawJSON!;
2060-
expect(raw.some_future_field).toBe("unexpected_value");
2061-
expect(raw.source_attached_function_id).toBe("func-123");
2062-
});
2063-
2064-
it("rawJSON with CMEK", async () => {
2065-
const schema = new Schema();
2066-
const cmek = Cmek.gcp("projects/p/locations/l/keyRings/r/cryptoKeys/k");
2067-
schema.setCmek(cmek);
2068-
2069-
const json = schema.serializeToJSON();
2070-
const deserialized = await Schema.deserializeFromJSON(json, client);
2071-
2072-
const raw = deserialized!.rawJSON!;
2073-
expect(raw.cmek).toEqual({
2074-
gcp: "projects/p/locations/l/keyRings/r/cryptoKeys/k",
2075-
});
2076-
});
2077-
2078-
it("rawJSON is null after deserializeFromJSON with null input", async () => {
2079-
const deserialized = await Schema.deserializeFromJSON(null, client);
2080-
expect(deserialized).toBeUndefined();
2081-
});
2082-
2083-
it("rawJSON roundtrip: re-serialized schema differs from rawJSON when lossy", async () => {
2084-
// Simulate a server response with extra fields that serializeToJSON would drop
2085-
const serverJson = {
2086-
defaults: {
2087-
string: {
2088-
fts_index: { enabled: false, config: {} },
2089-
string_inverted_index: { enabled: true, config: {} },
2090-
},
2091-
},
2092-
keys: {},
2093-
source_attached_function_id: "func-abc",
2094-
};
2095-
2096-
const deserialized = await Schema.deserializeFromJSON(serverJson, client);
2097-
2098-
// rawJSON preserves the original
2099-
expect(deserialized!.rawJSON!.source_attached_function_id).toBe("func-abc");
2100-
2101-
// serializeToJSON does NOT include source_attached_function_id
2102-
const reserialized = deserialized!.serializeToJSON();
2103-
expect((reserialized as any).source_attached_function_id).toBeUndefined();
2104-
});
21051970
});

0 commit comments

Comments
 (0)