Package: vsslite
VSSLiteA vector similarity search engine for humans🥳🎁 Install$pipinstallvsslite✨ FeaturesVSSLite provides a user-friendly interface for langchain and sqlite-vss.🧩 Start API server$exportOPENAI_APIKEY="YOUR_API_KEY"$python-mvssliteOrimportuvicornfromvssliteimportLangChainVSSLiteServerapp=LangChainVSSLiteServer(YOUR_API_KEY).appuvicorn.run(app,host="127.0.0.1",port=8000)Gohttp://127.0.0.1:8000/docsto know the details and try it out.🔍 SearchfromvssliteimportLangChainVSSLiteClient# Initializevss=LangChainVSSLiteClient()# Add data with embeddingsvss.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.")# Searchprint(vss.search("fish",count=1))print(vss.search("animal",count=1))print(vss.search("food",count=1))Now you can get these search results.$pythonrun.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.# Addid=vss.add("The difference between eel and conger eel is that eel is more expensive.")[0]# Getvss.get(id)# Updatevss.update(id,"The difference between eel and conger eel is that eel is more expensive. Una-jiro is cheaper than both of them.")# Deletevss.delete(id)# Delete allvss.delete_all()Upload data. Accept Text, PDF, CSV and JSON for now.vss.upload("path/to/data.json")🍻 AsynchronousUse async methods when you use VSSLite in server apps.awaitvss.aadd("~~~")awaitvss.aupdate(id,"~~~")awaitvss.aget(id)awaitvss.adelete(id)awaitvss.aupdate_all()awaitvss.asearch("~~~")awaitvss.aupload("~~~")🧇 NamespaceVSSLite supports namespaces for dividing the set of documents to search or update.vss=LangChainVSSLiteClient()# Search product documentsvss.search("What is the difference between super size and ultra size?",namespace="product")# Search company documentsvss.search("Who is the CTO of Unagiken?",namespace="company")🌐 Web UIYou can quickly launch a Q&A web service based on documents 🚅Install dependency$pipinstallstreamlit
$pipinstallstreamlit-chatMake a scriptThis is an example for OpenAI terms of use (upload terms of use to VSSServer with namespaceopenai).
Save this script asrunui.py.importasynciofromvsslite.chatimport(ChatUI,VSSQAFunction)# Setup QA functionopenai_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 functionverbose=True)# Start appchatui=ChatUI(temperature=0.5,functions=[openai_qa_func])asyncio.run(chatui.start())Start UI$streamlitrunrunui.pySeehttps://docs.streamlit.ioto know more about Streamlit.💬 LINE BotYou can quickly launch a LINE Bot based on documents 🛫Install dependency$pipinstallaiohttpline-bot-sdkMake a scriptThis is an example for OpenAI terms of use (upload terms of use to VSSServer with namespaceopenai).
Save this script asline.py.importosfromvsslite.chatgpt_processorimportVSSQAFunctionfromvsslite.lineimportLineBotServer# Setup QA function(s)fromvsslite.chatgpt_processorimportVSSQAFunctionopenai_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 functionverbose=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 Developersfunctions=[openai_qa_func]).appStart LINE Bot Webhook Server$uvicornline:app--host0.0.0.0--port8002Set `https://your_domain/linebot`` to webhook url at LINE Developers.🐳 DockerIf you want to start VSSLite API with chat console, usedocker-compose.ymlin examples.Set your OpenAI API Key in vsslite.env and execute the command below:$docker-compose-pvsslite--env-filevsslite.envup-d--buildOr, use Dockerfile to start each service separately.$dockerbuild-tvsslite-api-fDockerfile.api.
$dockerrun--namevsslite-api--mounttype=bind,source="$(pwd)"/vectorstore,target=/app/vectorstore-d-p8000:8000-eOPENAI_API_KEY=$OPENAI_API_KEYvsslite-api:latest$dockerbuild-tvsslite-chat-fDockerfile.chat.
$dockerrun--namevsslite-chat-d-p8001:8000-eOPENAI_API_KEY=$OPENAI_API_KEYvsslite-chat:latest🌊 Using Azure OpenAI ServiceVSSLite supports Azure OpenAI Service👍API ServerUseOpenAIEmbeddingsconfigured for Azure.fromlangchain.embeddingsimportOpenAIEmbeddingsazure_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_KEYoros.getenv("OPENAI_API_KEY"),persist_directory="./vectorstore",chunk_size=500,chunk_overlap=0,embedding_function=azure_embeddings).appChat UICreateChatUIwith Azure OpenAI Service configurations.chatui=ChatUI(apikey=YOUR_API_KEYoros.getenv("OPENAI_API_KEY"),temperature=0.5,functions=[openai_qa_func],# Config for Azure OpenAI Serviceapi_type="azure",api_base="https://your-endpoint.openai.azure.com/",api_version="2023-08-01-preview",engine="your-embeddings-deployment-name")See also theexamples.🍪 Classic version (based on SQLite)Seev0.3.0 README🥰 Special thankssqlite-vss:https://github.com/asg017/sqlite-vsshttps://note.com/mahlab/n/n5d59b19be573https://qiita.com/Hidetoshi_Kawaguchi/items/f84f7a43d5d1c15a5a17https://zenn.dev/koron/articles/8925963f432361