Skip to main content

🍑👋

Project description

spanking 🍑👋

To use the 🍑👋 VectorDB class, you can follow these steps:

  1. Create an instance of the 🍑👋 VectorDB class:
from spanking import VectorDB
vector_db = VectorDB(model_name='BAAI/bge-base-en-v1.5')

You can optionally specify a different pre-trained sentence transformer model by passing its name to the constructor.

  1. Add texts to the database:
texts = ["i eat pizza", "i play chess", "i drive bus"]
vector_db.add_texts(texts)

This will encode the texts into embeddings and store them in the database.

  1. Search for similar texts:
query = "we play football"
top_results = vector_db.search(query, top_k=3)
print(top_results)

This will retrieve the top-3 most similar texts to the query based on cosine similarity. The search method returns a list of tuples, where each tuple contains the text and its similarity score.

  1. Delete a text from the database:
index = 1
vector_db.delete_text(index)

This will remove the text and its corresponding embedding at the specified index.

  1. Update a text in the database:
index = 0
new_text = "i enjoy eating pizza"
vector_db.update_text(index, new_text)

This will update the text and its corresponding embedding at the specified index with the new text.

  1. Save the database to a file:
vector_db.save('vector_db.pkl')

This will save the current state of the VectorDB instance to a file named 'vector_db.pkl'.

  1. Load the database from a file:
vector_db = VectorDB.load('vector_db.pkl')

This will load the VectorDB instance from the file named 'vector_db.pkl' and return it.

  1. Iterate over the stored texts:
for text in vector_db:
    print(text)

This will iterate over all the texts stored in the database.

  1. Access individual texts by index:
index = 2
text = vector_db[index]
print(text)

This will retrieve the text at the specified index.

  1. Get the number of texts in the database:
num_texts = len(vector_db)
print(num_texts)

This will return the number of texts currently stored in the database.

Here's an example usage of the 🍑👋 VectorDB class:

from spanking import VectorDB
vector_db = VectorDB()

# Add texts to the database
texts = ["i eat pizza", "i play chess", "i drive bus"]
vector_db.add_texts(texts)

# Search for similar texts
query = "we play football"
top_results = vector_db.search(query, top_k=2)
print("Top results:")
for text, similarity in top_results:
    print(f"Text: {text}, Similarity: {similarity}")

# Update a text
vector_db.update_text(1, "i enjoy playing chess")

# Delete a text
vector_db.delete_text(2)

# Save the database
vector_db.save('vector_db.pkl')

# Load the database
loaded_vector_db = VectorDB.load('vector_db.pkl')

# Iterate over the stored texts in the loaded database
print("\nStored texts in the loaded database:")
for text in loaded_vector_db:
    print(text)

This example demonstrates how to create a 🍑👋 VectorDB instance, add texts, search for similar texts, update and delete texts, and iterate over the stored texts.

Project details


Download files

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

Source Distribution

spanking-0.1.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

spanking-0.1.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file spanking-0.1.0.tar.gz.

File metadata

  • Download URL: spanking-0.1.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for spanking-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9f3fd1b0ca71b5a0fbfe6e8448ae49611a6009b7b5e7fe0a95185f73abf8bdbb
MD5 d3b30f202242c6994386e15a10dbe598
BLAKE2b-256 7ee4d153f3a4d6839923052485f8494466402a3a1301f557b996ff1f1695bbb3

See more details on using hashes here.

File details

Details for the file spanking-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spanking-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for spanking-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6fdee888e92ea06d2e6b9bf133bbc80179011a3f7a791df6dcb896f1e29832d
MD5 07ac18b0e698cc683b7b5111eb3565b6
BLAKE2b-256 dde263be6d7b2c29f0183bc889ab1ecd11bf3f2c2ac2a0cd70c422b640ee4d7f

See more details on using hashes here.

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