Skip to main content
Epsilla 是一款开源向量数据库,利用先进的并行图遍历技术进行向量索引。Epsilla 基于 GPL-3.0 协议授权。
使用此集成前,请通过 pip install -qU langchain-community 安装 langchain-community 本 Notebook 展示与 Epsilla 向量数据库相关的功能使用方法。 作为前提条件,您需要有一个正在运行的 Epsilla 向量数据库(例如通过我们的 Docker 镜像),并安装 pyepsilla 包。完整文档请参阅 docs
!pip/pip3 install pyepsilla
我们希望使用 OpenAIEmbeddings,因此需要获取 OpenAI API Key。
import getpass
import os

if "OPENAI_API_KEY" not in os.environ:
    os.environ["OPENAI_API_KEY"] = getpass.getpass("OpenAI API Key:")
OpenAI API Key: ········
from langchain_community.vectorstores import Epsilla
from langchain_openai import OpenAIEmbeddings
from langchain_community.document_loaders import TextLoader
from langchain_text_splitters import CharacterTextSplitter

loader = TextLoader("../../how_to/state_of_the_union.txt")
documents = loader.load()

documents = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0).split_documents(
    documents
)

embeddings = OpenAIEmbeddings()
Epsilla 向量数据库默认运行在主机 “localhost” 的 8888 端口。我们使用自定义的数据库路径、数据库名称和集合名称,而非默认值。
from pyepsilla import vectordb

client = vectordb.Client()
vector_store = Epsilla.from_documents(
    documents,
    embeddings,
    client,
    db_path="/tmp/mypath",
    db_name="MyDB",
    collection_name="MyCollection",
)
query = "What did the president say about Ketanji Brown Jackson"
docs = vector_store.similarity_search(query)
print(docs[0].page_content)
In state after state, new laws have been passed, not only to suppress the vote, but to subvert entire elections. We cannot let this happen. Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.