forked from run-llama/LlamaIndexTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restore missing exports (run-llama#610)
- Loading branch information
Showing
4 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
"llamaindex": patch | ||
"@llamaindex/core-test": patch | ||
--- | ||
|
||
- Add missing exports: | ||
- `IndexStructType`, | ||
- `IndexDict`, | ||
- `jsonToIndexStruct`, | ||
- `IndexList`, | ||
- `IndexStruct` | ||
- Fix `IndexDict.toJson()` method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export * from "./BaseIndex.js"; | ||
export * from "./IndexStruct.js"; | ||
export * from "./json-to-index-struct.js"; | ||
export * from "./keyword/index.js"; | ||
export * from "./summary/index.js"; | ||
export * from "./vectorStore/index.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { | ||
IndexDict, | ||
IndexList, | ||
IndexStruct, | ||
IndexStructType, | ||
MetadataMode, | ||
TextNode, | ||
jsonToIndexStruct, | ||
} from "llamaindex"; | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe("jsonToIndexStruct", () => { | ||
it("transforms json to IndexDict", () => { | ||
function isIndexDict(some: IndexStruct): some is IndexDict { | ||
return "type" in some && some.type === IndexStructType.SIMPLE_DICT; | ||
} | ||
|
||
const node = new TextNode({ text: "text", id_: "nodeId" }); | ||
const expected = new IndexDict(); | ||
expected.addNode(node); | ||
|
||
console.log("expected.toJson()", expected.toJson()); | ||
const actual = jsonToIndexStruct(expected.toJson()); | ||
|
||
expect(isIndexDict(actual)).toBe(true); | ||
expect( | ||
(actual as IndexDict).nodesDict.nodeId.getContent(MetadataMode.NONE), | ||
).toEqual("text"); | ||
}); | ||
it("transforms json to IndexList", () => { | ||
function isIndexList(some: IndexStruct): some is IndexList { | ||
return "type" in some && some.type === IndexStructType.LIST; | ||
} | ||
|
||
const node = new TextNode({ text: "text", id_: "nodeId" }); | ||
const expected = new IndexList(); | ||
expected.addNode(node); | ||
|
||
const actual = jsonToIndexStruct(expected.toJson()); | ||
|
||
expect(isIndexList(actual)).toBe(true); | ||
expect((actual as IndexList).nodes[0]).toEqual("nodeId"); | ||
}); | ||
it("fails for unknown index type", () => { | ||
expect(() => { | ||
const json = { | ||
indexId: "dd120b16-8dce-4ce3-9bb6-15ca87fe4a1d", | ||
summary: undefined, | ||
nodesDict: {}, | ||
type: "FOO", | ||
}; | ||
return jsonToIndexStruct(json); | ||
}).toThrowError("Unknown index struct type: FOO"); | ||
}); | ||
it("fails for unknown node type", () => { | ||
expect(() => { | ||
const json = { | ||
indexId: "dd120b16-8dce-4ce3-9bb6-15ca87fe4a1d", | ||
summary: undefined, | ||
nodesDict: { | ||
nodeId: { | ||
...new TextNode({ text: "text", id_: "nodeId" }).toJSON(), | ||
type: "BAR", | ||
}, | ||
}, | ||
type: IndexStructType.SIMPLE_DICT, | ||
}; | ||
return jsonToIndexStruct(json); | ||
}).toThrowError("Invalid node type: BAR"); | ||
}); | ||
}); |