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

hnswlib: Throw error in index getter to dedupe code and have safer usage #35

Merged
merged 1 commit into from
Feb 24, 2023

Conversation

micahriggan
Copy link
Contributor

@micahriggan micahriggan commented Feb 17, 2023

Feel free to close, but seems like we can provide safer access to .index with a getter that throws if it hasn't been init'd

Also added a static method to init the HNSW Lib so we don't have to dupe the error handling each time

Oh yeah, thanks for making this, super cool

@micahriggan micahriggan force-pushed the feature/safer-index-usage branch 2 times, most recently from 1c6452e to 698e840 Compare February 17, 2023 21:59
@micahriggan micahriggan changed the title Throw error in index getter to dedupe code and have safer usage hnswlib: Throw error in index getter to dedupe code and have safer usage Feb 17, 2023
@sullivan-sean
Copy link
Collaborator

Great call! This cleans things up nicely.

@nfcampos
Copy link
Collaborator

Another option would be to make the index property private, if you need access to it you can always create the instance with an index created outside?

@micahriggan
Copy link
Contributor Author

Yeah you could make it private, and you could use

HNSWLib.getHierarchicalNSW(args) in the other files instead of accessing index. You might have to re-init the index that way though. I only noticed 2 places that were external to this file accessing the index property, but I didn't dig into whether they relied on it being initialized already

@nfcampos nfcampos changed the base branch from main to nc/esm February 24, 2023 10:07
@nfcampos
Copy link
Collaborator

Thanks so much for this @micahriggan , I've rebased this and pulling this in now

@nfcampos nfcampos merged this pull request into langchain-ai:nc/esm Feb 24, 2023
nfcampos added a commit that referenced this pull request Feb 27, 2023
* Use fetch adapter for openai axios

* Update tsc build to output ESM only

* Update all import paths to have extension per ESM requirements

* Move all source files to src/

* Remove circular dependency

* Fix jest config for ESM

* Remove circular deps not possible with ESM

* Throw error in index getter to dedupe code and have safer usage (#35)

* Fix hnsw for esm

* Fix usage of hnswlib with index passed in

* Fix textsplitter for esm

* Fix openai for esm

* Fix hf for esm

* Fix ESM for cohere

* Fix ESM for serpapi

* Fix esm in srt

* Remove dependency on @vespaiach/axios-fetch-adapter which has an incorrect export

* Fix examples for esm

* Fix entrypoints

* Fix test-exports for esm

* Add fetch flag for node 16 ci job

* Add a more thorough test for packaging

* Fix docs build

---------

Co-authored-by: micahriggan <micahriggan@users.noreply.github.com>
nfcampos added a commit that referenced this pull request Feb 27, 2023
* Add integration tests GH action (manual trigger for now), reduce cost of integration tests by using smallest possible models

* Convert library to ESM codebase, ESM output (#124)

* Use fetch adapter for openai axios

* Update tsc build to output ESM only

* Update all import paths to have extension per ESM requirements

* Move all source files to src/

* Remove circular dependency

* Fix jest config for ESM

* Remove circular deps not possible with ESM

* Throw error in index getter to dedupe code and have safer usage (#35)

* Fix hnsw for esm

* Fix usage of hnswlib with index passed in

* Fix textsplitter for esm

* Fix openai for esm

* Fix hf for esm

* Fix ESM for cohere

* Fix ESM for serpapi

* Fix esm in srt

* Remove dependency on @vespaiach/axios-fetch-adapter which has an incorrect export

* Fix examples for esm

* Fix entrypoints

* Fix test-exports for esm

* Add fetch flag for node 16 ci job

* Add a more thorough test for packaging

* Fix docs build

---------

Co-authored-by: micahriggan <micahriggan@users.noreply.github.com>

---------

Co-authored-by: micahriggan <micahriggan@users.noreply.github.com>
nfcampos added a commit that referenced this pull request Feb 27, 2023
…rt library to ESM codebase, ESM output (#124), Add GH (manual) action for running integration tests (#119)

* Use fetch adapter for openai axios

* Remove node-fetch, add instructions for node 16

* Add GH (manual) action for running integration tests (#119)

* Add integration tests GH action (manual trigger for now), reduce cost of integration tests by using smallest possible models

* Convert library to ESM codebase, ESM output (#124)

* Use fetch adapter for openai axios

* Update tsc build to output ESM only

* Update all import paths to have extension per ESM requirements

* Move all source files to src/

* Remove circular dependency

* Fix jest config for ESM

* Remove circular deps not possible with ESM

* Throw error in index getter to dedupe code and have safer usage (#35)

* Fix hnsw for esm

* Fix usage of hnswlib with index passed in

* Fix textsplitter for esm

* Fix openai for esm

* Fix hf for esm

* Fix ESM for cohere

* Fix ESM for serpapi

* Fix esm in srt

* Remove dependency on @vespaiach/axios-fetch-adapter which has an incorrect export

* Fix examples for esm

* Fix entrypoints

* Fix test-exports for esm

* Add fetch flag for node 16 ci job

* Add a more thorough test for packaging

* Fix docs build

---------

Co-authored-by: micahriggan <micahriggan@users.noreply.github.com>

---------

Co-authored-by: micahriggan <micahriggan@users.noreply.github.com>

* Fix one more import

* Fix example

* Also build docs in ci

* Fix sql test in ci

---------

Co-authored-by: micahriggan <micahriggan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants