A vector database wrapper on OpenSearch backend. [An alternative to Pinecone]
Project description
Opencone
A Pinecone alternative written on top of OpenSearch by simplifying features of OpenSearch
Requirements
- Install OpenSearch Backend
- or You can use a cloud hosted OpenSearch Backend
Python libraries
pip3 install opensearch-py
Usage
from opencone import OpenconeClient
import random
import numpy as np
import time
from opensearchpy import OpenSearch
host = 'localhost'
port = 9200
auth = ('admin', 'admin') # For testing only. Don't store credentials in code.
# Create an OpenSearch client
client = OpenSearch(
hosts=[{"host": host, "port": port}],
http_auth=auth,
use_ssl=True,
verify_certs=False,
ssl_assert_hostname=False,
ssl_show_warn=False
)
oc = OpenconeClient(client=client)
# Create an index
dimensions = 4096
t = time.time()
try:
oc.create_index(index_name="test", dimensions=dimensions)
except Exception as ex:
if "resource_already_exists_exception" in str(ex):
oc.delete_index(index_name="test")
oc.create_index(index_name="test", dimensions=dimensions)
else:
raise ex
print("Index created in ", time.time()-t)
# Upsert vectors
titles = ["pp", "qq", "rr", "ss", "tt"]
tags = ["p1", "p2", "p3", "p4", "p5"]
vectors = []
for i in range(100):
vectors.append((
"id:"+str(i),
np.random.randint(5, size=dimensions).tolist(),
{
"name": titles[random.randint(0, 4)],
"tags": tags[random.randint(0, 4):random.randint(0, 4)],
"no": random.randint(2000, 3000)
}
))
t = time.time()
oc.upsert(index_name="test", vectors=vectors)
print("Upsert time:", time.time()-t)
# Fetch vector
print(oc.fetch(index_name="test", _id="id:1"))
# Delete vector
print(oc.delete(index_name="test", _id="id:1"))
# Search
filters = {
"no": {"$gte":2200, "$lte":2800},
"name": {"$eq": "pp"},
"tags": {"$in": ["p1", "t3"]}
}
t = time.time()
rs = oc.search(index_name="test", vector=(np.random.randint(5, size=dimensions)/1.1).tolist(), filters=filters, metadata=False, limit=10000)
print("Search time:", time.time()-t)
for each in rs:
print(each)
# Delete index
oc.delete_index(index_name="test")
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
opencone-0.0.2.tar.gz
(36.2 MB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opencone-0.0.2.tar.gz.
File metadata
- Download URL: opencone-0.0.2.tar.gz
- Upload date:
- Size: 36.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f4271026ed3c761c19f6638aa8f641d3e1d3eb475e7f78a29dc6168e3a732c4
|
|
| MD5 |
6a166c6c27313843548251fc1140ac35
|
|
| BLAKE2b-256 |
78b5462930b3311312eacc0c90eaf21e6bb2d641842dfbbf3457d60a44a8c221
|
File details
Details for the file opencone-0.0.2-py3-none-any.whl.
File metadata
- Download URL: opencone-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3005e5b24af170ec3ce460f77d87ce75c7e503e71324905eaa9987fa6d36898e
|
|
| MD5 |
22498a7e48cdeb54f5f757319b59e7b5
|
|
| BLAKE2b-256 |
ed7d2559e7a83555bfbc3af17759f7be59a3895f540839a37aea87bbfc3a1e14
|