Name | vsslite JSON |
Version |
0.6.1
JSON |
| download |
home_page | https://github.com/uezo/vsslite |
Summary | A vector similarity search engine for humans๐ฅณ |
upload_time | 2023-10-29 14:50:24 |
maintainer | uezo |
docs_url | None |
author | uezo |
requires_python | |
license | MIT |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# VSSLite
A vector similarity search engine for humans๐ฅณ
# ๐ Install
```sh
$ pip install vsslite
```
# โจ Features
VSSLite provides a user-friendly interface for langchain and sqlite-vss.
## ๐งฉ Start API server
```sh
$ export OPENAI_APIKEY="YOUR_API_KEY"
$ python -m vsslite
```
Or
```python
import uvicorn
from vsslite 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
```python
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.
```bash
$ 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.
```python
# 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.
```python
vss.upload("path/to/data.json")
```
## ๐ป Asynchronous
Use async methods when you use VSSLite in server apps.
```python
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.
```python
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
```sh
$ pip install streamlit
$ pip install streamlit-chat
```
## Make a script
This is an example for OpenAI terms of use (upload terms of use to VSSServer with namespace `openai`).
Save this script as `runui.py`.
```python
import asyncio
from vsslite.chat import (
ChatUI,
VSSQAFunction
)
# Setup QA function
openai_qa_func = VSSQAFunction(
name="get_openai_terms_of_use",
description="Get information about terms of use of OpenAI services including ChatGPT.",
parameters={"type": "object", "properties": {}},
namespace="openai",
# answer_lang="Japanese", # <- Uncomment if you want to get answer in Japanese
# is_always_on=True, # <- Uncomment if you want to always fire this function
verbose=True
)
# Start app
chatui = ChatUI(temperature=0.5, functions=[openai_qa_func])
asyncio.run(chatui.start())
```
## Start UI
```sh
$ streamlit run runui.py
```
See https://docs.streamlit.io to know more about Streamlit.
# ๐ฌ LINE Bot
You can quickly launch a LINE Bot based on documents ๐ซ
## Install dependency
```sh
$ pip install aiohttp line-bot-sdk
```
## Make a script
This is an example for OpenAI terms of use (upload terms of use to VSSServer with namespace `openai`).
Save this script as `line.py`.
```python
import os
from vsslite.chatgpt_processor import VSSQAFunction
from vsslite.line import LineBotServer
# Setup QA function(s)
from vsslite.chatgpt_processor import VSSQAFunction
openai_qa_func = VSSQAFunction(
name="get_openai_terms_of_use",
description="Get information about terms of use of OpenAI services including ChatGPT.",
parameters={"type": "object", "properties": {}},
vss_url=os.getenv("VSS_URL") or "http://127.0.0.1:8000",
namespace="openai",
# answer_lang="Japanese", # <- Uncomment if you want to get answer in Japanese
# is_always_on=True, # <- Uncomment if you want to always fire this function
verbose=True
)
app = LineBotServer(
channel_access_token=YOUR_CHANNEL_ACCESS_TOKEN,
channel_secret=YOUR_CHANNEL_SECRET,
endpoint_path="/linebot", # <- Set "https://your_domain/linebot" to webhook url at LINE Developers
functions=[openai_qa_func]
).app
```
## Start LINE Bot Webhook Server
```sh
$ uvicorn line:app --host 0.0.0.0 --port 8002
```
Set `https://your_domain/linebot`` to webhook url at LINE Developers.
# ๐ณ Docker
If you want to start VSSLite API with chat console, use `docker-compose.yml` in examples.
Set your OpenAI API Key in vsslite.env and execute the command below:
```sh
$ docker-compose -p vsslite --env-file vsslite.env up -d --build
```
Or, use Dockerfile to start each service separately.
```sh
$ docker build -t vsslite-api -f Dockerfile.api .
$ docker run --name vsslite-api --mount type=bind,source="$(pwd)"/vectorstore,target=/app/vectorstore -d -p 8000:8000 -e OPENAI_API_KEY=$OPENAI_API_KEY vsslite-api:latest
```
```sh
$ docker build -t vsslite-chat -f Dockerfile.chat .
$ docker run --name vsslite-chat -d -p 8001:8000 -e OPENAI_API_KEY=$OPENAI_API_KEY vsslite-chat:latest
```
# ๐ Using Azure OpenAI Service
VSSLite supports Azure OpenAI Service๐
## API Server
Use `OpenAIEmbeddings` configured for Azure.
```python
from langchain.embeddings import OpenAIEmbeddings
azure_embeddings = OpenAIEmbeddings(
openai_api_type="azure",
openai_api_base="https://your-endpoint.openai.azure.com/",
openai_api_version="2023-08-01-preview",
deployment="your-embeddings-deployment-name"
)
app = LangChainVSSLiteServer(
apikey=YOUR_API_KEY or os.getenv("OPENAI_API_KEY"),
persist_directory="./vectorstore",
chunk_size=500,
chunk_overlap=0,
embedding_function=azure_embeddings
).app
```
## Chat UI
Create `ChatUI` with Azure OpenAI Service configurations.
```python
chatui = ChatUI(
apikey=YOUR_API_KEY or os.getenv("OPENAI_API_KEY"),
temperature=0.5,
functions=[openai_qa_func],
# Config for Azure OpenAI Service
api_type="azure",
api_base="https://your-endpoint.openai.azure.com/",
api_version="2023-08-01-preview",
engine="your-embeddings-deployment-name"
)
```
See also the [examples](https://github.com/uezo/vsslite/tree/main/examples).
# ๐ช Classic version (based on SQLite)
See [v0.3.0 README](https://github.com/uezo/vsslite/blob/6cee7e0421b893ed9e16fba0508e025270e2550a/README.md)
# ๐ฅฐ Special thanks
- sqlite-vss: https://github.com/asg017/sqlite-vss
- https://note.com/mahlab/n/n5d59b19be573
- https://qiita.com/Hidetoshi_Kawaguchi/items/f84f7a43d5d1c15a5a17
- https://zenn.dev/koron/articles/8925963f432361
Raw data
{
"_id": null,
"home_page": "https://github.com/uezo/vsslite",
"name": "vsslite",
"maintainer": "uezo",
"docs_url": null,
"requires_python": "",
"maintainer_email": "uezo@uezo.net",
"keywords": "",
"author": "uezo",
"author_email": "uezo@uezo.net",
"download_url": "",
"platform": null,
"description": "# VSSLite\n\nA vector similarity search engine for humans\ud83e\udd73\n\n\n# \ud83c\udf81 Install\n\n```sh\n$ pip install vsslite\n```\n\n\n# \u2728 Features\n\nVSSLite provides a user-friendly interface for langchain and sqlite-vss.\n\n\n## \ud83e\udde9 Start API server\n\n```sh\n$ export OPENAI_APIKEY=\"YOUR_API_KEY\"\n$ python -m vsslite\n```\n\nOr\n\n```python\nimport uvicorn\nfrom vsslite import LangChainVSSLiteServer\n\napp = LangChainVSSLiteServer(YOUR_API_KEY).app\nuvicorn.run(app, host=\"127.0.0.1\", port=8000)\n```\n\nGo http://127.0.0.1:8000/docs to know the details and try it out.\n\n\n## \ud83d\udd0d Search\n\n```python\nfrom vsslite import LangChainVSSLiteClient\n\n# Initialize\nvss = LangChainVSSLiteClient()\n\n# Add data with embeddings\nvss.add(\"The difference between eel and conger eel is that eel is more expensive.\")\nvss.add(\"Red pandas are smaller than pandas, but when it comes to cuteness, there is no \\\"lesser\\\" about them.\")\nvss.add(\"There is no difference between \\\"Ohagi\\\" and \\\"Botamochi\\\" themselves; they are used interchangeably depending on the season.\")\n\n# Search\nprint(vss.search(\"fish\", count=1))\nprint(vss.search(\"animal\", count=1))\nprint(vss.search(\"food\", count=1))\n```\n\nNow you can get these search results.\n\n```bash\n$ python run.py\n\n[{'page_content': 'The difference between eel and conger eel is that eel is more expensive.', 'metadata': {'source': 'inline'}}]\n[{'page_content': 'Red pandas are smaller than pandas, but when it comes to cuteness, there is no \"lesser\" about them.', 'metadata': {'source': 'inline'}}]\n[{'page_content': 'There is no difference between \"Ohagi\" and \"Botamochi\" themselves; they are used interchangeably depending on the season.', 'metadata': {'source': 'inline'}}]\n```\n\n## \ud83d\udd27 Data management (Add, Get, Update, Delete)\n\nHelps CRUD.\n\n```python\n# Add\nid = vss.add(\"The difference between eel and conger eel is that eel is more expensive.\")[0]\n# Get\nvss.get(id)\n# Update\nvss.update(id, \"The difference between eel and conger eel is that eel is more expensive. Una-jiro is cheaper than both of them.\")\n# Delete\nvss.delete(id)\n# Delete all\nvss.delete_all()\n```\n\nUpload data. Accept Text, PDF, CSV and JSON for now.\n\n```python\nvss.upload(\"path/to/data.json\")\n```\n\n\n## \ud83c\udf7b Asynchronous\n\nUse async methods when you use VSSLite in server apps.\n\n```python\nawait vss.aadd(\"~~~\")\nawait vss.aupdate(id, \"~~~\")\nawait vss.aget(id)\nawait vss.adelete(id)\nawait vss.aupdate_all()\nawait vss.asearch(\"~~~\")\nawait vss.aupload(\"~~~\")\n```\n\n\n## \ud83e\uddc7 Namespace\n\nVSSLite supports namespaces for dividing the set of documents to search or update.\n\n```python\nvss = LangChainVSSLiteClient()\n\n# Search product documents\nvss.search(\"What is the difference between super size and ultra size?\", namespace=\"product\")\n# Search company documents\nvss.search(\"Who is the CTO of Unagiken?\", namespace=\"company\")\n```\n\n\n# \ud83c\udf10 Web UI\n\nYou can quickly launch a Q&A web service based on documents \ud83d\ude85\n\n## Install dependency\n\n```sh\n$ pip install streamlit\n$ pip install streamlit-chat\n```\n\n## Make a script\n\nThis is an example for OpenAI terms of use (upload terms of use to VSSServer with namespace `openai`).\nSave this script as `runui.py`.\n\n```python\nimport asyncio\nfrom vsslite.chat import (\n ChatUI,\n VSSQAFunction\n)\n\n# Setup QA function\nopenai_qa_func = VSSQAFunction(\n name=\"get_openai_terms_of_use\",\n description=\"Get information about terms of use of OpenAI services including ChatGPT.\",\n parameters={\"type\": \"object\", \"properties\": {}},\n namespace=\"openai\",\n # answer_lang=\"Japanese\", # <- Uncomment if you want to get answer in Japanese\n # is_always_on=True, # <- Uncomment if you want to always fire this function\n verbose=True\n)\n\n# Start app\nchatui = ChatUI(temperature=0.5, functions=[openai_qa_func])\nasyncio.run(chatui.start())\n```\n\n## Start UI\n\n```sh\n$ streamlit run runui.py\n```\n\nSee https://docs.streamlit.io to know more about Streamlit.\n\n\n\n# \ud83d\udcac LINE Bot\n\nYou can quickly launch a LINE Bot based on documents \ud83d\udeeb\n\n## Install dependency\n\n```sh\n$ pip install aiohttp line-bot-sdk\n```\n\n## Make a script\n\nThis is an example for OpenAI terms of use (upload terms of use to VSSServer with namespace `openai`).\nSave this script as `line.py`.\n\n```python\nimport os\nfrom vsslite.chatgpt_processor import VSSQAFunction\nfrom vsslite.line import LineBotServer\n\n# Setup QA function(s)\nfrom vsslite.chatgpt_processor import VSSQAFunction\nopenai_qa_func = VSSQAFunction(\n name=\"get_openai_terms_of_use\",\n description=\"Get information about terms of use of OpenAI services including ChatGPT.\",\n parameters={\"type\": \"object\", \"properties\": {}},\n vss_url=os.getenv(\"VSS_URL\") or \"http://127.0.0.1:8000\",\n namespace=\"openai\",\n # answer_lang=\"Japanese\", # <- Uncomment if you want to get answer in Japanese\n # is_always_on=True, # <- Uncomment if you want to always fire this function\n verbose=True\n)\n\napp = LineBotServer(\n channel_access_token=YOUR_CHANNEL_ACCESS_TOKEN,\n channel_secret=YOUR_CHANNEL_SECRET,\n endpoint_path=\"/linebot\", # <- Set \"https://your_domain/linebot\" to webhook url at LINE Developers\n functions=[openai_qa_func]\n).app\n```\n\n## Start LINE Bot Webhook Server\n\n```sh\n$ uvicorn line:app --host 0.0.0.0 --port 8002\n```\n\nSet `https://your_domain/linebot`` to webhook url at LINE Developers.\n\n\n# \ud83d\udc33 Docker\n\nIf you want to start VSSLite API with chat console, use `docker-compose.yml` in examples.\n\nSet your OpenAI API Key in vsslite.env and execute the command below:\n\n```sh\n$ docker-compose -p vsslite --env-file vsslite.env up -d --build\n```\n\nOr, use Dockerfile to start each service separately.\n\n```sh\n$ docker build -t vsslite-api -f Dockerfile.api .\n$ docker run --name vsslite-api --mount type=bind,source=\"$(pwd)\"/vectorstore,target=/app/vectorstore -d -p 8000:8000 -e OPENAI_API_KEY=$OPENAI_API_KEY vsslite-api:latest\n```\n```sh\n$ docker build -t vsslite-chat -f Dockerfile.chat .\n$ docker run --name vsslite-chat -d -p 8001:8000 -e OPENAI_API_KEY=$OPENAI_API_KEY vsslite-chat:latest\n```\n\n# \ud83c\udf0a Using Azure OpenAI Service\n\nVSSLite supports Azure OpenAI Service\ud83d\udc4d\n\n## API Server\n\nUse `OpenAIEmbeddings` configured for Azure.\n\n```python\nfrom langchain.embeddings import OpenAIEmbeddings\nazure_embeddings = OpenAIEmbeddings(\n openai_api_type=\"azure\",\n openai_api_base=\"https://your-endpoint.openai.azure.com/\",\n openai_api_version=\"2023-08-01-preview\",\n deployment=\"your-embeddings-deployment-name\"\n)\n\napp = LangChainVSSLiteServer(\n apikey=YOUR_API_KEY or os.getenv(\"OPENAI_API_KEY\"),\n persist_directory=\"./vectorstore\",\n chunk_size=500,\n chunk_overlap=0,\n embedding_function=azure_embeddings\n).app\n```\n\n## Chat UI\n\nCreate `ChatUI` with Azure OpenAI Service configurations.\n\n```python\nchatui = ChatUI(\n apikey=YOUR_API_KEY or os.getenv(\"OPENAI_API_KEY\"),\n temperature=0.5,\n functions=[openai_qa_func],\n # Config for Azure OpenAI Service\n api_type=\"azure\",\n api_base=\"https://your-endpoint.openai.azure.com/\",\n api_version=\"2023-08-01-preview\",\n engine=\"your-embeddings-deployment-name\"\n)\n```\n\nSee also the [examples](https://github.com/uezo/vsslite/tree/main/examples).\n\n\n# \ud83c\udf6a Classic version (based on SQLite)\n\nSee [v0.3.0 README](https://github.com/uezo/vsslite/blob/6cee7e0421b893ed9e16fba0508e025270e2550a/README.md)\n\n\n# \ud83e\udd70 Special thanks\n\n- sqlite-vss: https://github.com/asg017/sqlite-vss\n- https://note.com/mahlab/n/n5d59b19be573\n- https://qiita.com/Hidetoshi_Kawaguchi/items/f84f7a43d5d1c15a5a17\n- https://zenn.dev/koron/articles/8925963f432361\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A vector similarity search engine for humans\ud83e\udd73",
"version": "0.6.1",
"project_urls": {
"Homepage": "https://github.com/uezo/vsslite"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "05ec9ee302a329832e257e6a240e1e691fa83b1fecc9633e047a95d8e1fb18dd",
"md5": "5ad144f9f7b4234b1084added6bab38b",
"sha256": "7ea888a634c7340d6d80db254bde9f54d77ba30ffe73b9f32b1362917384cd44"
},
"downloads": -1,
"filename": "vsslite-0.6.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5ad144f9f7b4234b1084added6bab38b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 21128,
"upload_time": "2023-10-29T14:50:24",
"upload_time_iso_8601": "2023-10-29T14:50:24.235610Z",
"url": "https://files.pythonhosted.org/packages/05/ec/9ee302a329832e257e6a240e1e691fa83b1fecc9633e047a95d8e1fb18dd/vsslite-0.6.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-29 14:50:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "uezo",
"github_project": "vsslite",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "vsslite"
}