Skip to main content

A vector similarity search engine for humans🥳

Project description

VSSLite

A vector similarity search engine for humans🥳

🎁 Install

$ pip install vsslite

✨ Features

VSSLite provides a user-friendly interface for langchain and sqlite-vss.

🧩 Start API server

$ export OPENAI_APIKEY="YOUR_API_KEY"
$ python -m vsslite

Or

import uvicorn
from server import LangChainVSSLiteServer

app = LangChainVSSLiteServer(YOUR_API_KEY).app
uvicorn.run(app, host="127.0.0.1", port=8000)

Go http://127.0.0.1:8000/docs to know the details and try it out.

🔍 Search

from vsslite import LangChainVSSLiteClient

# Initialize
vss = LangChainVSSLiteClient()

# Add data with embeddings
vss.add("The difference between eel and conger eel is that eel is more expensive.")
vss.add("Red pandas are smaller than pandas, but when it comes to cuteness, there is no \"lesser\" about them.")
vss.add("There is no difference between \"Ohagi\" and \"Botamochi\" themselves; they are used interchangeably depending on the season.")

# Search
print(vss.search("fish", count=1))
print(vss.search("animal", count=1))
print(vss.search("food", count=1))

Now you can get these search results.

$ python run.py

[{'page_content': 'The difference between eel and conger eel is that eel is more expensive.', 'metadata': {'source': 'inline'}}]
[{'page_content': 'Red pandas are smaller than pandas, but when it comes to cuteness, there is no "lesser" about them.', 'metadata': {'source': 'inline'}}]
[{'page_content': 'There is no difference between "Ohagi" and "Botamochi" themselves; they are used interchangeably depending on the season.', 'metadata': {'source': 'inline'}}]

🔧 Data management (Add, Get, Update, Delete)

Helps CRUD.

# Add
id = vss.add("The difference between eel and conger eel is that eel is more expensive.")[0]
# Get
vss.get(id)
# Update
vss.update(id, "The difference between eel and conger eel is that eel is more expensive. Una-jiro is cheaper than both of them.")
# Delete
vss.delete(id)
# Delete all
vss.delete_all()

Upload data. Accept Text, PDF, CSV and JSON for now.

vss.upload("path/to/data.json")

🍻 Asynchronous

Use async methods when you use VSSLite in server apps.

await vss.aadd("~~~")
await vss.aupdate(id, "~~~")
await vss.aget(id)
await vss.adelete(id)
await vss.aupdate_all()
await vss.asearch("~~~")
await vss.aupload("~~~")

🧇 Namespace

VSSLite supports namespaces for dividing the set of documents to search or update.

vss = LangChainVSSLiteClient()

# Search product documents
vss.search("What is the difference between super size and ultra size?", namespace="product")
# Search company documents
vss.search("Who is the CTO of Unagiken?", namespace="company")

💬 Web UI

You can quickly launch a Q&A web service based on documents 🚅

Install dependency

$ pip install streamlit

Make a script

This is an example for OpenAI terms of use. Save as runui.py.

import asyncio
from vsslite import LangChainVSSLiteClient
from vsslite.chat import (
    ChatUI,
    ChatGPTFunctionBase,
    ChatGPTFunctionResponse
)

class OpenAIQAFunction(ChatGPTFunctionBase):
    name="get_openai_terms_of_use"
    description="Get information about terms of use of OpenAI services including ChatGPT."
    parameters={"type": "object", "properties": {}}

    def __init__(self) -> None:
        super().__init__()
        self.vss = LangChainVSSLiteClient()

    async def aexecute(self, question_text: str, **kwargs) -> ChatGPTFunctionResponse:
        qprompt = """
Please respond to user questions based on the following conditions.

## Conditions

* The 'information to be based on' below is OpenAI's terms of service. Please create responses based on this content.
* While multiple pieces of information are provided, you do not need to use all of them. Use one or two that you consider most important.
* When providing your response, quote and present the part you referred to, which is highly important for the user.
* Please respond **in Japanese**, regardless of the language of the reference material.
* The response format should be as follows:

----
{Response}

Quotation: {Relevant part of the information to be based on}
----

## Information to be based on

"""
        sr = await self.vss.asearch(question_text, namespace="openai")
        for d in sr:
            qprompt += d["page_content"] + "\n\n------------\n\n"
        
        # See the generated prompt
        print(qprompt)

        return ChatGPTFunctionResponse(qprompt, "user")


chatui = ChatUI(YOUR_API_KEY, temperature=0.5, functions=[OpenAIQAFunction()])
asyncio.run(chatui.start())

Start UI

$ streamlit run runui.py

See https://docs.streamlit.io to know more about Streamlit.

🍪 Classic version (based on SQLite)

See v0.3.0 README

🥰 Special thanks

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

vsslite-0.4.1-py3-none-any.whl (16.4 kB view hashes)

Uploaded Python 3

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