Let's see how we can quickly use citrus to index texts and perform semantic search!
We'll only focus on the core citrusdb functions. For production, you'd likely implement the same on a server. Tutorials for that coming soon!
# Install via pip
pip install --upgrade citrusdb
Before we can insert vectors, we need to create an index.
citrus = citrusdb.Client()
This will create a client for interacting with our index. We then create the index itself with some configurations options. Check out the API reference later to find how you can play around with this.
We're also choosing to persist our data inside the
dbdirectory. This will ensure that our data remains saved and in the future, citrusdb can load the index from there.
ids = [0, 1, 2]
docuemnts = [
"Your time is limited, so don't waste it living someone else's life",
"I'd rather be optimistic and wrong than pessimistic and right.",
"Running a start-up is like chewing glass and staring into the abyss."
You can directly pass vector embeddings as well. If you're passing a list of strings like we have done here, ensure you have your
OPENAI_API_KEYin the environment. By default we use OpenAI to generate the embeddings. Please reach out if you're looking for support from a different provider (or submit a PR 😉)!
results, distances = citrus.query(
"What is it like to launch a startup",
for id in results: