Package: nautilusdb-client
nautilusdb-python-clientPython client forNautilusDB, a fully-managed, cloud-native chat service.NautilusDB is currently inpublic alpha. We're actively improving
the product and releasing new features, and we'd love to hear your feedback!
Please take a moment to fill out thisfeedback formto help us understand your use-case better.By default, all collections are subject to permanent deletion after 2 weeks. Please let us know if you need to keep it for longer via the feedback form.NautilusDB python client provides very simple APIs for you to directly upload files and ask questions.QuickstartYou can try out NautilusDB in just a few lines of code. We have
prepared a special public collectionopenai-webthat can answer
questions about the contents ofwww.openai.comimportnautilusdbasndbanswer,_=ndb.collection('openai-web').ask('what is red team?')print(answer)"""Sample answer:Red team refers to the group of external experts who work with OpenAI toidentify and evaluate potential risks and harmful capabilities in new systems.The red team's role is to help develop taxonomies of risk and provide inputthroughout the model and product development lifecycle."""You can also create your own collections, upload files, then get answers
specific to your data assets. The following example walks you through the
process of creating a collection and indexingthe original transformer paperinto that collection.importnautilusdbasndb# Create an API keymy_api_key=ndb.create_api_key()# Configure ndb to use the newly minted API keyndb.init(api_key=my_api_key)# Create a new collectionllm_research=ndb.Collection(name="llm_research")ndb.create_collection(llm_research)# Index the original Transformer paper into this collection.llm_research.upload_document("https://arxiv.org/pdf/1706.03762.pdf")# Get answers from this paperllm_research.ask("what is a transformer?")InstallationInstall a released NautilusDB python client from pip.python3 version>= 3.10is requiredpip3installnautilusdb-clientCreating an API keyYou need an API key to create, update, delete own collections. A collection
can only be accessed by the API key that created it.Account management and related functionalities will be released soon.importnautilusdbasndb# Create a new API keymy_api_key=ndb.create_api_key()# Please record this API key and keep it a secrete## Collections created with this key can only be accessed# through this key!print(my_api_key)# Use this API key in all subsequent callsndb.init(api_key=my_api_key)Creating a CollectionSeethis pagefor a brief overview of NautilusDB data modelYou can create a collection that is only accessible with a specific API key.importnautilusdbasndbndb.init(api_key="<my_api_key>")# Create a collection called llm_researchcollection=ndb.Collection(name='llm_research')ndb.create_collection(collection)Listing collectionYou can see list of collections you have access to. For example, this list
will include all collections that were created using the currently configured
API key.importnautilusdbasndbndb.init(api_key="<my_api_key>")collections=ndb.list_collections()Uploading a documentYou can upload a local file or a file from a web URL and index it into a
collection.Supported file format.pdfPDF files.csvCSV files.txtPlain-text files.mdMarkdown files.docxMicrosoft word documentsimportnautilusdbasndbndb.init(api_key="<my_api_key>")# llm_research collection was created in the previous stepcollection=ndb.collection('llm_research')# Local file and URLs are both supported.# URL must contain the full scheme prefix (http:// or https://)collection.upload_document('/path/to/file.pdf')collection.upload_document('https://path/to/file.pdf')Crawl a websiteYou can pass the website root url. NautilusDB will automatically crawl it.importnautilusdbasndbndb.init(api_key="<my_api_key>")# Create the crawl taskcollection=ndb.Collection(name='example-web')ndb.create_collection(collection)crawl_id=collection.create_crawl('https://www.example.com')# Query the crawl statusresp=collection.get_crawl(crawl_id)# check resp.crawl_status becomes CrawlStatus.SUCCEEDED, and index the pagescollection.index_crawl(crawl_id)Asking a questionYou can ask questions within a collection. API key is required for private
collections only.ask()method returns a plain-text answer to
your question, as well as a list of most relevance references used to derive
the answer.Available public collections that do not require an API key to accessopenai-web: Contains contents ofwww.openai.comimportnautilusdbasndbndb.init(api_key="<my_api_key>")# Get a plain text answer, as well as a list of references from the collection# that are the most relevant to the question.answer,refs=ndb.collection('openai-web').ask('what is red team?')answer,refs=ndb.collection('llm_research').ask('what is a transformer?')Deleting a collectionYou can delete a collection using the same API key that was used to create it.importnautilusdbasndbndb.init(api_key="<my_api_key>")ndb.delete_collection('llm_research')