Skip to main content

Simple Wrapper for vector database in Python with minimal support for CRUD and retrieve.

Project description

PyVectorDB

Simple Wrapper for vector database in Python with minimal support for CRUD and retrieve.

Installation

pip install pyvectordb

Usage Example

PGVector

PGvector is an extension for PostgreSQL that allows the storage, indexing, and querying of vector embeddings. It is designed to support vector similarity search, which is useful in machine learning applications like natural language processing, image recognition, and recommendation systems. By storing vector embeddings as a data type, PGvector enables efficient similarity searches using distance metrics such as cosine similarity, Euclidean distance, inner product, etc.

import os
from pyvectordb import PgvectorDB, Vector
from pyvectordb.distance_function import DistanceFunction

v = Vector(
    embedding=[2., 2., 1.]
)

print("VECTOR", v)

pgv = PgvectorDB(
    db_user=os.getenv("PG_USER"),
    db_password=os.getenv("PG_PASSWORD"),
    db_host=os.getenv("PG_HOST"),
    db_port=os.getenv("PG_PORT"),
    db_name=os.getenv("PG_NAME"),
    collection=os.getenv("PG_COLLECTION"),
    distance_function=DistanceFunction.L2,
)

new_v = pgv.create_vector(v)
print("CREATE_VECTOR", new_v)

new_v = pgv.read_vector(new_v.id)
print("READ_VECTOR", new_v)

new_v = pgv.update_vector(new_v)
print("UPDATE_VECTOR", new_v)

for x in pgv.get_neighbor_vectors(v, 5):
    print(f"{x}")

pgv.delete_vector(new_v.id)
print("DELETE_VECTOR")

Qdrant

Qdrant “is a vector similarity search engine that provides a production-ready service with a convenient API to store, search, and manage points (i.e. vectors) with an additional payload.” You can think of the payloads as additional pieces of information that can help you hone in on your search and also receive useful information that you can give to your users.

Using Qdrant in pyvectordb is simple, you only need to change the client to QdrantDB

from pyvectordb import QdrantDB

qv = QdrantDB(
    host=os.getenv("Q_HOST"),
    api_key=os.getenv("Q_API_KEY"),
    port=os.getenv("Q_PORT"),
    collection=os.getenv("Q_COLLECTION"),
    vector_size=int(os.getenv("Q_SIZE")),
    distance_function=DistanceFunction.COSINE,
)

Chroma DB

Chroma is the AI-native open-source vector database. Chroma makes it easy to build LLM apps by making knowledge, facts, and skills pluggable for LLMs.

from pyvectordb import ChromaDB

ch = ChromaDB(
    host=os.getenv("CH_HOST"),
    port=os.getenv("CH_PORT"),
    auth_provider=os.getenv("CH_AUTH_PROVIDER"),
    auth_credentials=os.getenv("CH_AUTH_CREDENTIALS"),
    collection_name=os.getenv("CH_COLLECTION_NAME"),
    distance_function=DistanceFunction.L2,
)

Support or Anything

Reach me out on email razifrizqullah@gmail.com

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

pyvectordb-0.1.3.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

pyvectordb-0.1.3-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file pyvectordb-0.1.3.tar.gz.

File metadata

  • Download URL: pyvectordb-0.1.3.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.6 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for pyvectordb-0.1.3.tar.gz
Algorithm Hash digest
SHA256 627f5a5901dc01e05c3968ed24062087611f7c4640924984816731539c9d0ee8
MD5 2f17149123ba3c8b6276bb98150d6661
BLAKE2b-256 486c020528414e13f0517c10cc1a59501885a04c9043470d8108728d605d27f9

See more details on using hashes here.

File details

Details for the file pyvectordb-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pyvectordb-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.6 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for pyvectordb-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 57b4546f02457691127481f823ef73062d7857ff6d2fd26e05755ab4a9d474ce
MD5 f7c5b2eb858b5db6e1527a576c04b167
BLAKE2b-256 ad916716e5a32fd6f4def780988854bb9401cc6f9f30237bf67c4c8d11150c6f

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