pulled code out of nomic api codebase