Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Mario Alberto Chávez
Mario Alberto Chávez

Posted on • Originally published atmariochavez.io on

Chroma Vector Database Ruby client

Post originally published athttps://mariochavez.io/desarrollo/2023/05/15/chroma-vector-database-ruby-client/


Today I’m releasing a gem calledchroma-db which is a Ruby client forChroma Vector Database.

Chroma defines itself as “the AI-native open-source embedding database”. The interest in Vector Databases increased with the popularity of LLMs, these types of databases became the context memory for them.

My desire to start playing around with LLMs, especially the ones that you can run on your own, let me to the place to start writing tools for the Ruby language.

The server

To install Chroma locally, it requires a Python environment. There are many ways to install Python on your system. Choose the one that works better for you.

Here I’ll useminiconda installed viaHomeBrew on macOS.

$ brew install miniconda$ conda activate chroma
Enter fullscreen modeExit fullscreen mode

Once the environment is ready, in my case, instead of installing Chroma via pip command I choose to clone the repo with a specific tag.

$ git clone --depth 1 --branch 0.3.22  git@github.com:chroma-core/chroma.git
Enter fullscreen modeExit fullscreen mode

To start the server, go to Chroma cloned directory and use docker to create the image and start the service with Docker Compose.

$ docker-compose up -d --build
Enter fullscreen modeExit fullscreen mode

This command starts the server athttp://localhost:8000 but also starts theClickhouse which is used by Chroma to persists embeddings, metadata, and documents.

The client

With the server up and running, the next step is to install the client, and then you are ready.

To install the client, just run

$ gem install chroma-db
Enter fullscreen modeExit fullscreen mode

Or add it to your Gemfile with

$ bundle add chroma-db
Enter fullscreen modeExit fullscreen mode

Here is an example of a few operations with Chroma.

require "logger"# Requiere Chroma Ruby client.require "chroma-db"# Configure Chroma's host. Here you can specify your own host.Chroma.connect_host = "http://localhost:8000"Chroma.logger = Logger.new($stdout)Chroma.log_level = Chroma::LEVEL_ERROR# Check current Chrome server versionversion = Chroma::Resources::Database.versionputs version# Create a new collectioncollection = Chroma::Resources::Collection.create(collection_name, {lang: "ruby", gem: "chroma-db"})# Add embeddingsembeddings = [  Chroma::Resources::Embedding.new(id: "1", embedding: [1.3, 2.6, 3.1], metadata: {client: "chroma-rb"}, document: "ruby"),  Chroma::Resources::Embedding.new(id: "2", embedding: [3.7, 2.8, 0.9], metadata: {client: "chroma-rb"}, document: "rails")]collection.add(embeddings)
Enter fullscreen modeExit fullscreen mode

Jupyter notebook

To explore a more complete example, chroma-db repository includesJupyter notebook. To use the notebook, install the following Python dependencies and install theIRuby kernel.


Jupyter notebook

$ pip install jupyterlab notebook ipywidgets$ gem install iruby$ iruby register --force
Enter fullscreen modeExit fullscreen mode


Jupyter notebook

Final

The work of LLMs is very popular now days, tooling in the Python and JavaScript world is moving very fast. Ruby has always been excluded from ML or NLP technology.

There is an opportunity for Ruby tools in the “chain” areas to connect and integrate services around the LLMs. If you feel the same, please contribute to improving this client and to create other tools that we can use in our Ruby world.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Long time Rubyst and photographer.
  • Location
    Colima
  • Joined

More fromMario Alberto Chávez

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp