Giter VIP home page Giter VIP logo

chromaphp's Introduction

chromaPHP

chromaPHP is a PHP client for Chroma, the open-source embedding database. Chroma makes it easy to build LLM apps by making knowledge, facts, and skills pluggable for LLMs.

chromaPHP provides a simple way to interact with Chroma using PHP.

Requirements

  • PHP 7.0 or later
  • The cURL extension for PHP

Installation

You can install chromaPHP using Composer. Simply add the following to your composer.json file:

json

{
    "require": {
        "yourname/chromaphp": "^1.0"
    }
}

Then run composer install to install the library and its dependencies.

Usage

To use chromaPHP, you'll need to first create a client instance by passing in the base URL of your Chroma server:

php

$client = new chromaPHP("http://localhost:8000");

You can then use the client object to perform various operations on your Chroma collections. Here's an example that demonstrates creating a collection, adding some embeddings to it, querying for nearest neighbors of a query embedding, and then deleting the collection:

php

// Create a new collection
$collectionName = "my_collection";
$metadata = ["name" => "John", "age" => 30];
$getOrCreate = false;
echo "Creating collection '$collectionName'...\n";
$start = microtime(true);
$response = $client->createCollection($collectionName, $metadata, $getOrCreate);
$elapsed = microtime(true) - $start;
echo "Response: $response\n";
echo "Time elapsed: $elapsed seconds\n\n";

// Add embeddings to the collection
$embeddings = [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]];
$metadatas = [["name" => "Alice", "age" => 25], ["name" => "Bob", "age" => 40]];
$documents = ["document1", "document2"];
$ids = ["id1", "id2"];
$incrementIndex = false;
echo "Adding embeddings to collection '$collectionName'...\n";
$start = microtime(true);
$response = $client->addEmbedding($collectionName, $embeddings, $metadatas, $documents, $ids, $incrementIndex);
$elapsed = microtime(true) - $start;
echo "Response: $response\n";
echo "Time elapsed: $elapsed seconds\n\n";

// Query for nearest neighbors of a query embedding
$queryEmbeddings = [[0.2, 0.3, 0.4]];
$nResults = 2;
$include = [];
echo "Querying for nearest neighbors of query embedding in collection '$collectionName'...\n";
$start = microtime(true);
$response = $client->getNearestNeighbors($collectionName, $queryEmbeddings, $nResults, $include);
$elapsed = microtime(true) - $start;
echo "Response: $response\n";
echo "Time elapsed: $elapsed seconds\n\n";

// Clean up by deleting the collection
echo "Deleting collection '$collectionName'...\n";
$start = microtime(true);
$response = $client->deleteCollection($collectionName);
$elapsed = microtime(true) - $start;
echo "Response: $response\n";
echo "Time elapsed: $elapsed seconds\n\n";

Note that the chromaPHP client provides methods for all of the operations supported by Chroma, including creating and deleting collections, adding embeddings, querying for nearest neighbors, and more.

Contributing

Contributions are welcome! If you encounter any bugs or issues while using chromaPHP, please open an issue on the GitHub repository and we'll do our best to resolve it. If you would like to contribute a new feature or improvement, please open a pull request.

chromaphp's People

Contributors

africanrhino avatar

Stargazers

Dariusz Debowczyk avatar  avatar Jimmy avatar  avatar  avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.