Skip to main content

VectorVault: Simplified vector database management in the cloud for machine learning and generative ai workflows

Project description

alt text

Vector Vault is a cloud vector database service that was built to make generative ai chat quick and easy. It allows users to vectorize data easily and access them seamlessly from the cloud. It's suitable for both small projects and large. Vector Vault has been designed with a user-friendly code interface to make the process of working with vector data easy and let you focus on what matters, results. Vector Vault ensures secure and isolated data handling and enables you to create and interact vector databases - aka "vaults" - in the cloud, at millisecond response times.

By combining vector similarity search with generative ai chat, new possibilities for conversation and communication emerge. For example, product information can be added to a vault, and when a customer asks a product question, the right product information can be instantly retreived and seamlessly used in conversation by chatgpt for an accurate response. This capability allows for informed conversation and the possibilites range from ai automated customer support, to new ways to get news, to ai code reviews that reference source documentation, to ai domain experts for specific knowledge sets, and much more.

Vector Vault uses a proprietary architecture, called "Inception", allowing you to create any number of vaults, and vaults within a vaults. Each vault is it's own database, and automatically integrates data storage in the cloud. You will need a Vector Vault api key in order to access the cloud vaults. If you don't already have one, you can use the included register() function or sign up at VectorVault.io

The vectorvault package allows you to interact with your Cloud Vaults using its Python-based API. Each vault is a seperate vector database. vectorvault includes operations such as creating a vault, deleting a vault, preparing data to add, getting vector embeddings for prepared data using OpenAI's text-embedding-ada-002, saving the data and embeddings to the cloud, referencing cloud vault data via vector search and retrieval, interacting with OpenAI's ChatGPT model to get responses, managing conversation history, and retrieving contextualized responses with reference vault data as context.


Basic Interactions:

add() : Prepares data to be added to the Vault, with automatic text splitting and processing for long texts.
get_vectors() : Retrieves vectors embeddings for all prepared data
save() : Saves the data with embeddings to the Vault (cloud), along with any metadata
delete() : Deletes the current Vault and all contents
get_vaults() : Retrieves a list of Vaults within the current Vault directory
get_similar() : Retrieves similar texts from the Vault for a given input text
get_chat() : Retrieves a response from ChatGPT, with support for handling conversation history, summarizing responses, and retrieving context-based responses by referencing similar data in the vault

get_vectors() utilizes openai embeddings api and internally batches vector embeddings with OpenAI's text-embeddings-ada-002 model, and comes with auto rate-limiting and concurrent requests for maximum processing speed


Interact with your Vault:

Install Vector Vault:

pip install vector-vault

Get Your Vector Vault API Key:

from vectorvault import register

register(first_name='John', last_name='Smith', email='john@smith.com', password='make_a_password')

The api key will be sent to your email.


Use Vector Vault:

Set your openai key as an envorionment variable

os.environ['OPENAI_API_KEY'] = 'your_openai_api_key'
  1. Create a Vault instance - (new vault will be created if name does not exist)
  2. Gather some text data we want to store
  3. Add the data to the Vault
  4. Get vectors embeddings
  5. Save to the cloud vault
from vectorvault import Vault

vault = Vault(user='your@email.com', api_key='your_api_key', vault='name_of_vault)

text_data = 'some data'

vault.add(text_data)

vault.get_vectors()

vault.save()


Now that you have saved some data to the vault, you can add more at anytime, and your vault will automatically handle the adding process. These three lines execute very fast.

vault.add(more_text_data)

vault.get_vectors()

vault.save()


vault.add() is very versitile. You can add any length of text, even a full book...and it will be all automatically split and processed. vault.get_vectors() is also extremely flexible, because you can vault.add() as much as you want, then when you're done, process all the vectors at once with a vault.get_vectors() call - Which internally batches vector embeddings with OpenAI's text-embeddings-ada-002, and comes with auto rate-limiting and concurrent requests for maximum processing speed.

vault.add(insanely_large_text_data)
vault.get_vectors() 
vault.save() 

^ these three lines execute fast and can be called as often as you like. For example: you can use add(), get_vectors(), and save() mid conversation to save every message to the vault as soon as they comes in. Small loads are usually finished in less than a second. Large loads depend on total data size.

A test was done adding the full text of 37 books at once. The get_vectors() function took 8 minutes and 56 seconds. (For comparison, processing one at a time via openai's embedding function would take roughly two days)



Reference Your Vault:

After you've added some data and want to reference it later, you can call it like this:

similar_data = vault.get_similar("Your text input") 

for result in similar_data:
    print(result['data'])

^ this prints each similar item that was retieved. The get_similar() function retrieves items from the vault using vector cosine similarity search algorithm to find results. Default returns a list with 4 results. similar_data = vault.get_similar(text_input, n = 10) returns 10 results instead of 4.


Print the metadata:

similar_data = vault.get_similar("Your text input") 

for result in similar_data:
    print(result['data'])
    print(result['metadata'])

Metadata

To add meta data to your vault, just include the meta as a parameter in add(). Meta is always a dict, and you can add any fields you want. (If you don't add a 'name' field, a generic one will automatically be generated, so there is always a name field in the metadata)

meta = {
    'name': 'Lifestyle in LA',
    'country': 'United State',
    'city': 'LA' 
}

vault.add(text, meta)

vault.get_vectors()

vault.save()

To add just the 'name' field to the metadata, call the name param in add() like this:

vault.add(text, name='Lifestyle in LA')

vault.get_vectors()

vault.save()

To find the name later:

similar_data = vault.get_similar("Your text input") 

for result in similar_data:
    print(result['metadata']['name'])

Add Any Meta Fields & Retrieve later

Here we open the popular book by George Orwell, "1984", from a .txt file. We read the file and save all the book's text to a variable called "text". Then we create a dictionary containing all the information about the book. Then we save all that to the vault. When you call the vault later, you can reference any of the metadata. When referencing the vault with get_similar() or get_chat(text, get_context=True) the vault will return sample texts from the book, and if the vault has many books in it, you may want to know where that sample is coming from. The metadata is how you will know.

with open('1984.txt', 'r') as file:
    text = file.read()

book_metadata = {
    'title': '1984',
    'author': 'George Orwell',
    'genre': 'Dystopian',
    'publication_year': 1949,
    'publisher': 'Secker & Warburg',
    'ISBN': '978-0451524935',
    'language': 'English',
    'page_count': 328
}

vault.add(text, book_metadata)

vault.get_vectors()

vault.save()

To find the metadata later:

similar_data = vault.get_similar("How will the government control you in the future?") 

for result in similar_data:
    print(result['metadata']['title'])
    print(result['metadata']['author'])
    print(result['metadata']['genre'])
    # etc...

^ list is always returned. So you can break it down like above or like below...

similar_data = vault.get_similar("How will the government control you in the future?") 
print(similar_data[0]['metadata']['title'])


Use get_chat() with get_context=True to get response from chatgpt referencing vault data

Retrieving items from the vault, is useful when using it supply context to a large language model, like chatgpt for instance, to get a contextualized response. The follow example searches the vault for 4 similar results and then give those to chatgpt as context, asking chatgpt answer the question using the vault data.

question = "This text will be used find contextually similar references in the vault"

answer = vault.get_chat(question, get_context=True)  
print(answer)

The following line will send chatgpt the question for response and not interact with the vault in any way

answer = vault.get_chat(question) 


Change Vaults

In this example science vault, we will print a list of vaults in the current vault directory

science_vault = Vault(user='your_user_id', api_key='your_api_key', vault='science')

print(science_vault.get_vaults())

Output: ['biology', 'physics', 'chemistry']

Access vaults within vaults

  • biology vault within science vault
biology_vault = Vault(user='your@email.com', api_key='your_api_key', vault='science/biology')
  • chemistry vault within science vault
chemistry_vault = Vault(user='your@email.com', api_key='your_api_key', vault='science/chemistry')

print(chemistry_vault.get_vaults())

Output: ['reactions', 'formulas', 'lab notes']

  • lab notes vault within chemistry vault
lab_notes_vault = Vault(user='your@email.com', api_key='your_api_key', vault='science/chemistry/lab notes')


ChatGPT

With get_chat() you can use ChatGPT standalone or with Vault data integrated


Get chat response from OpenAI's ChatGPT. Rate limiting, auto retries, and chat histroy slicing auto-built-in so you can create complex chat capability without getting complicated. Enter your text, optionally add chat history, and optionally choose a summary response instead (default: summmary=False)

  • Example Signle Usage: response = vault.get_chat(text)

  • Example Chat: response = vault.get_chat(text, chat_history)

  • Example Summary: summary = vault.get_chat(text, summary=True)

  • Example Context-Based Response: response = vault.get_chat(text, get_context=True)

  • Example Context-Based Response w/ Chat History: response = vault.get_chat(text, chat_history, get_context=True)

  • Example Context-Response with Context Samples Returned: vault_response = vault.get_chat(text, get_context=True, return_context=True)


Response is a string, unless return_context=True is passed, then response will be a dictionary containing the results from the vault as well as the response:

# print response:
print(vault_response['response'])

# print context:
for item in vault_response['context']:
    print("\n\n", f"item {item['metadata']['name']}")
    print(item['data'])


Summarize Anything:

You can summarize any text, no matter how large - even an entire book all at once. Long texts are split into the largest possible chunk sizes and a summary is generated for each chunk. When all summaries are finished, they are concatenated and returned as one.

summary = vault.get_chat(text, summary=True)

want to make a summary of a certain length?...

summary = vault.get_chat(text, summary=True)

while len(summary) > 1000:
    summary = vault.get_chat(summary, summary=True)

^ in the above example, we make a summary, then we enter while loop that continues until the summary recieved back is a certain lenght. You could use this to summarize a 1000 page book to less than 1000 characters of text.




Real world usage:

user_input = input("What's your question?")

# Get response from Language model
vault_response = vault.get_chat(user_input, get_context=True, return_context=True)

answer = vault_response['response']
print("Question:", user_input, "\n\nAnswer:", answer)

# show the context used to generate the answer
for item in vault_response['context']:
    print("\n\n", f"item {item['metadata']['item_id']}")
    print(item['data'])

Output: Question: What is a token broker?

Answer: A token broker is a service that generates downscoped access tokens for token consumers to access or modify specific resources...

item 33 Various workloads (token consumers) in the same network will send authenticated requests to that broker for downscoped tokens to...

item 4 Another reason to use downscoped credentials is to ensure tokens in flight...

item 37 The following is an...


user_input2 = input("What's your next question?")

history = user_input + answer

# Get response from Language model
vault_response = vault.get_chat(user_input2, history=history, get_context=True)

print("Question:", user_input2, "\n\nAnswer:", vault_response2)

Output: Question: How do I use it?

Answer: You can use it by...




Build an AI Cusomter Service Chat Bot


In the following code, we will add all of a company's past support conversations to a vault. (The conversations are stored in a .txt file). As new people message in, we will search the vault for similar questions and answers. We take the past answers returned from the vault and instruct ChatGPT to use those previous answers to answer this new question. (NOTE: This will also work based on a customer FAQ, or customer support response templates).


Create the Customer Service Vault

from vectorvault import Vault

os.environ['OPENAI_API_KEY'] = 'your_openai_api_key'

vault = Vault(user='your_user_id', api_key='your_api_key', vault='Customer Service')

with open('customer_service.txt', 'r') as f:
    vault.add(f.read())

vault.get_vectors()

vault.save()

And just like that, in a only a few lines of code we created a customer service vault. Now whenever you want to use it in production, just connect to that vault, and use the get_chat() with get_context=True. When you call get_chat(text, get_context=True) it will take the customer's question, search the vault to find the most similar questions and answers, then have ChatGPT reply to the customer using that information.

question = 'customer question'

answer = vault.get_chat(question, get_context=True)

That's all it takes to create an AI customer service chatbot that responds as well as any support rep!






If have any questions, drop a message in our Discord channel, happy to help.

Open the "examples" folder and try out the Google Colab tutorials we have! They will show you a lot, plus they are in Google Colab, so no local set up required, just open them up and press play.




FAQ

What is the latency on large datasets?

To conceptualize "large", 37 full length book texts with vectors make up ~80MB of storage with around 10,000 - 15,000 items of ~1000 characters for each item. This example of 37 books is considered small. Free plans come with 1GB of storage, and 100MB/mo of uploading, so this doesn't even hit the free plan limit. Calling similar items from this vault is under one second response time with the similar items returned. This example is about the same amount of data as the entire customer support history for any given company. So if you build a typical customer service chatbot, your vault size will be considered small. If you had 10 times that much data, api latency may be around 5 seconds. Our architechture is optimized for lightning fast responses on small-medium size datasets, so if your data size grows to large amounts, and you see the call time taking longer than 1 second, its recommended that you segment you data into multiple vaults to keep latency below 1 second on api calls.

How should I segment my data?

Vaults within vaults is the optimal structure for segmenting data. If a vault grows too large, just make multiple child vaults within the current vault directory, and store the data there. If your 'Science' vault grows too large, split it into multiple child vaults, like 'Science/Chemistry', etc - this accesses a "Chemistry" vault within the Science vault. Now you can fine grain datasets, where every child vault contains more specific subject information than the parent vault. This segmenting structure allows you to focus data on large data sets. Keep in mind this only applies to very large data sets. Also, if your data set is large and you don't mind a little longer response times on vault call, then you don't need to do anything. In that case, you can just add it all to one vault and not worry about it.

What if I'm a large company with very large data

If you need to store large amounts of data in single vaults for whatever reason, let us know and we can set you up with Custom cloud plan. In our Custom plan, we create a persistent storage pod that is always active. With a Custom plan, a billion vectors search will respond in under one second. For reference, the full text of 3.7 million books would be around 1.1 - 1.5 billion vectors, and take up about 8 terabytes of storage. If this is what you're looking for, just reach out to us by email at support at vectorvault.io.


Happy coding!


Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vector_vault-1.3.0.tar.gz (18.9 kB view hashes)

Uploaded Source

Built Distribution

vector_vault-1.3.0-py3-none-any.whl (23.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page