Skip to main content

memvectorDB-python client

Getting Started

pip install memvectordb-python

VectorStore

from memvectordb.vectorstore import MemVectorDBVectorStore

Using Sentence Transformers

base_url = "vectordb-url"
embedding_provider = "sentence_transformers"  
embedding_model = "multi-qa-MiniLM-L6-cos-v1"  # Specific embedding model name 

collection_name = "collection_name"
distance = "distance-metric"        # either 'cosine', 'euclidean' or 'dot'

vector_store = MemVectorDBVectorStore(
    base_url=base_url,
    embedding_provider=embedding_provider,
    embedding_model=embedding_model,
)

vector_store.create_collection(collection_name, distance)

embedding_model_client = vector_store.initialize_embedding_model_client()

Using OpenAI Embeddings

base_url = "base-vectordb-url"
embedding_provider = "openai"  
embedding_model = "text-embedding-3-small"  # Specific embedding model name 

collection_name = "collection_name"
distance = "distance-metric"        # either 'cosine', 'euclidean' or 'dot'

vector_store = MemVectorDBVectorStore(
    base_url=base_url,
    embedding_provider=embedding_provider,
    embedding_model=embedding_model,
    api_key= "openai-api-key"
)

vector_store.create_collection(collection_name, distance)

embedding_model_client = vector_store.initialize_embedding_model_client()
# Upserting texts
text = "First text string"
vector_store.add_texts(collection_name, text, embedding_model_client)


# Upserting a text document
def load_doc(file_url):
    pages = []
    file_path = Path(file_url)

    file_extension = file_path.suffix
    if file_extension == ".pdf":
        loader = PyPDFLoader(file_url)
        pages = loader.load_and_split()
    return pages

doc = load_doc("https://arxiv.org/pdf/1706.03762.pdf")
vector_store.add_documents(collection_name, doc, embedding_model_client, streaming=True) 
# Streaming: configures how the pages are upserted into the DB ie batch or stream.

To Query Vectors.

k = "number-of-items-to query"
collection_name = "collection_name"
query_vector = "query_vector"

# example of query_vector: [0.32654, 0.24423, 0.7655] 
# ensure the dimensions match the collection's dimensions
vector_store.query(collection_name, k, query_vector)

Using Requests

pip install memvectordb-python

To Initialize the Client

from memvectordb.collection import Collection

client = MemVectorDB(base_url = "base-url") # default http://127.0.0.1:8000

To Create Collection

# To create a new collection
collection_name = "collection_name"
dimension = "dimension-of-vectors-to-be-stored"
distance = "distance-metric" # either 'cosine', 'euclidean' or 'dot'
collection = client.create_collection(collection_name, dimension, distance)

To Get Collection

collection_name = "collection_name"
collection = client.get_collection(collection_name)

To Delete collection

collection_name = "collection_name"
collection = client.delete_collection(collection_name)

To Insert Vectors(streaming)

collection_name = "collection_name"
embedding = {
    "id": {
        "unique_id": "1"
    },
    "vector": [0.14, 0.316, 0.433],
    "metadata": {
        "key1": "value1",
        "key2": "value2"
    }
}
client.insert_embeddings(
    collection_name=collection_name, 
    vector_id=embedding["id"]['unique_id'], 
    vector=embedding["vector"], 
    metadata=embedding["metadata"]
)

To Insert Vectors(batch)

collection_name = "collection_name"
embeddings = [
    {
        "id": {
            "unique_id": "0"
        },
        "vector": [0.14, 0.316, 0.433],
        "metadata": {
            "key1": "value1",
            "key2": "value2"
        }
    },
    {
        "id": {
            "unique_id": "1"
        },
        "vector": [0.27, 0.531, 0.621],
        "metadata": {
            "key1": "value3",
            "key2": "value4"
        }
    },
    {
        "id": {
            "unique_id": "2"
        },
        "vector": [0.27, 0.531, 0.621],
        "metadata": {
            "key1": "value3",
            "key2": "value4"
        }
    }
]

client.batch_insert_embeddings(
        collection_name=collection_name, 
        embeddings = embeddings
    )

To Query Vectors.

k = "number-of-items-to query"
collection_name = "collection_name"
query_vector = "query_vector"

# example of query_vector: [0.32654, 0.24423, 0.7655] 
# ensure the dimensions match the collection's dimensions
client.query(collection_name, k, query_vector)

Metadata

Release files for memvectordb-python 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for memvectordb-python 0.0.7
File Size Uploaded
memvectordb_python-0.0.7.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for memvectordb-python 0.0.7
File Interpreter ABI Platform
memvectordb_python-0.0.7-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 11.0 kB

Release files / memvectordb_python-0.0.7.tar.gz

Download URL memvectordb_python-0.0.7.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5997fa8c1ab089d28122ccbc615a7c395d02b10077a79cc77b8f7a2a8580c45f
BLAKE2b-256 checksum
How to use checksums
ac8ff39cbdeb001edcc0da8795b09779138afcab7c954c4b5d6304a98bd1b0c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Release files / memvectordb_python-0.0.7-py2.py3-none-any.whl

Download URL memvectordb_python-0.0.7-py2.py3-none-any.whl
Size 6.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
523b6c27c20be98a027c3b4191cc1d52b18c2afc95f3d001fbe24c8bb13dc7e2
BLAKE2b-256 checksum
How to use checksums
805e2dd743261471f86618190927f770253e1c092598d23ee83bbf98c824f2fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page