Package: vectra-py
vectra-pyThis is a faithful port of Steven Ickman'sVectrain memory vector index project. Only modifications were to port into python, adjust for format, and generate some python friendly example code. Below readme follows on from his, with similar pythonic adjustments.Thanks for the inspiriation Steve!Vectra-py is a local vector database for Python with features similar toPineconeorQdrantbut built using local files. Each Vectra index is a folder on disk. There's anindex.jsonfile in the folder that contains all the vectors for the index along with any indexed metadata.  When you create an index you can specify which metadata properties to index and only those fields will be stored in theindex.jsonfile. All of the other metadata for an item will be stored on disk in a separate file keyed by a GUID.When queryng Vectra you'll be able to use the same subset ofMongo DB query operatorsthat Pinecone supports and the results will be returned sorted by similarity. Every item in the index will first be filtered by metadata and then ranked for similarity. Even though every item is evaluated its all in memory so it should by nearly instantanious. Likely 1ms - 2ms for even a rather large index. Smaller indexes should be <1ms.Keep in mind that your entire Vectra index is loaded into memory so it's not well suited for scenarios like long term chat bot memory. Use a real vector DB for that. Vectra is intended to be used in scenarios where you have a small corpus of mostly static data that you'd like to include in your prompt. Infinite few shot examples would be a great use case for Vectra or even just a single document you want to ask questions over.Pinecone style namespaces aren't directly supported but you could easily mimic them by creating a separate Vectra index (and folder) for each namespace.InstallationWIP, run via example.py for the moment.Eventually:$ pip install vectra-pyPrepUse dotenv or set env var to store your openAI API Key.UsageFirst create an instance ofLocalIndexwith the path to the folder where you want you're items stored:fromsrc.local_indeximportLocalIndexindex=LocalIndex(os.path.join(os.getcwd(),'index'))Next, from inside an async function, create your index:ifnotindex.isIndexCreated():index.createIndex()Add some items to your index:openai.api_key=os.environ.get("OPENAI_APIKEY")asyncdefget_vector(text:str):print(text)model="text-embedding-ada-002"response=awaitopenai_async.embeddings(openai.api_key,timeout=2,payload={"model":model,"input":[text]},)returnresponse.json()['data'][0]['embedding']asyncdefadd_item(text:str):vector=awaitget_vector(text)metadata={'text':text}print(vector,metadata)awaitindex.insertItem({'vector':vector,'metadata':metadata})//Additemsawaitadd_item('apple');awaitadd_item('oranges');awaitadd_item('red');awaitadd_item('blue');Then query for items:asyncdefquery(text:str):vector=awaitget_vector(text)results=awaitindex.queryItems(vector,3)iflen(results)>0:forresultinresults:print(f"[{result['score']}]\{result.get('item')['metadata']['text']}")else:print("No results found.")awaitquery('green')/*[0.9036569942401076]blue[0.8758153664568566]red[0.8323828606103998]apple*/awaitquery('banana')/*[0.9033128691220631]apple[0.8493374123092652]oranges[0.8415324469533297]blue*/