Skip to content

Commit

Permalink
Merge pull request #7 from BlackyDrum/cpp-20
Browse files Browse the repository at this point in the history
1.0.0 Release
  • Loading branch information
BlackyDrum authored Oct 19, 2024
2 parents dcaa2c7 + 7c7a868 commit a292519
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 29 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ jobs:
- name: Initialize submodules
run: git submodule update --init --recursive

- name: Install GCC 13
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update
sudo apt-get install -y gcc-13 g++-13
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 60
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 60
gcc --version
g++ --version
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y cmake libssl-dev
run: sudo apt-get install -y cmake libssl-dev

- name: Configure CMake
run: cmake -S . -B build
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [1.0.0] - 2024-10-19
### Changed
- Updated the C++ standard from C++17 to C++20.
- Renamed the function `GetLastRequestAdditionalMetadata()` to `GetRequestMetadata()` for clarity.
- Replaced string concatenation with `std::format` for more readable formatting.

## [0.4.3] - 2024-10-11
### Changed
- Replaced `push_back` with `emplace_back`
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.10)
project(chromadb VERSION 0.4.3)
project(chromadb VERSION 1.0.0)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

if (MSVC)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ This guide will help you build and install the ChromaDB library and run an examp

### Prerequisites
- CMake (version 3.10 or higher)
- A C++ compiler (supporting C++17)
- A C++ compiler (supporting C++20)
- OpenSSL development libraries

### Building ChromaDB Library
Expand Down Expand Up @@ -529,7 +529,7 @@ int main()
- **path**: (Optional) The path of the endpoint for generating embeddings. Defaults to `/v1/embeddings`.

### Getting Additional Metadata from Embedding Requests
If you generated embeddings using an embedding function that calls a provider (e.g., OpenAI or Jina), you can retrieve additional information about the request using the `embeddingFunction->GetLastRequestAdditionalMetadata()` method. This function returns specific metadata for a provider.
If you generated embeddings using an embedding function that calls a provider (e.g., OpenAI or Jina), you can retrieve additional information about the request using the `embeddingFunction->GetRequestMetadata()` method. This function returns specific metadata for a provider.

```cpp
#include "ChromaDB/ChromaDB.h"
Expand All @@ -545,7 +545,7 @@ int main()

client.AddEmbeddings(collection, ids, {}, {}, documents);

std::cout << embeddingFunction->GetLastRequestAdditionalMetadata() << std::endl;
std::cout << embeddingFunction->GetRequestMetadata() << std::endl;
// Example output (specific for the Jina API):
// {
// "model": "jina-embeddings-v2-base-en",
Expand All @@ -557,7 +557,7 @@ int main()
// }

// Access specific fields in the additional metadata
std::cout << embeddingFunction->GetLastRequestAdditionalMetadata()["usage"]["prompt_tokens"] << std::endl; // 8
std::cout << embeddingFunction->GetRequestMetadata()["usage"]["prompt_tokens"] << std::endl; // 8
}

```
Expand Down
1 change: 1 addition & 0 deletions include/ChromaDB/Client/ChromaApiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Json/json.h"

#include <string>
#include <format>

namespace chromadb {

Expand Down
1 change: 1 addition & 0 deletions include/ChromaDB/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <unordered_map>
#include <unordered_set>
#include <regex>
#include <format>

namespace chromadb {

Expand Down
2 changes: 1 addition & 1 deletion include/ChromaDB/Embeddings/EmbeddingFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace chromadb {

virtual std::vector<std::vector<double>> Generate(const std::vector<std::string>& documents) = 0;

nlohmann::json GetLastRequestAdditionalMetadata() const { return m_LastRequestAdditionalMetadata; }
nlohmann::json GetRequestMetadata() const { return m_LastRequestAdditionalMetadata; }
protected:
std::string m_BaseUrl;
std::string m_Path;
Expand Down
1 change: 1 addition & 0 deletions include/ChromaDB/Resources/Collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <memory>
#include <map>
#include <format>

namespace chromadb {

Expand Down
2 changes: 1 addition & 1 deletion src/ChromaDB/Client/ChromaApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace chromadb {
ChromaApiClient::ChromaApiClient(const std::string& scheme, const std::string& host, const std::string& port, const std::string& authToken)
: m_Scheme(scheme), m_Host(host), m_Port(port), m_AuthToken(authToken)
{
m_BaseUrl = m_Scheme + "://" + m_Host + ":" + m_Port;
m_BaseUrl = std::format("{}://{}:{}", m_Scheme, m_Host, m_Port);
}

nlohmann::json ChromaApiClient::Get(const std::string& endpoint)
Expand Down
38 changes: 19 additions & 19 deletions src/ChromaDB/Client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace chromadb {
{
try
{
m_ChromaApiClient.Get("/tenants/" + m_Tenant);
m_ChromaApiClient.Get(std::format("/tenants/{}", m_Tenant));
}
catch (ChromaException)
{
Expand All @@ -21,7 +21,7 @@ namespace chromadb {

try
{
m_ChromaApiClient.Get("/databases/" + m_Database + "?tenant=" + m_Tenant);
m_ChromaApiClient.Get(std::format("/databases/{}?tenant={}", m_Database, m_Tenant));
}
catch (ChromaException)
{
Expand Down Expand Up @@ -53,7 +53,7 @@ namespace chromadb {

try
{
m_ChromaApiClient.Post("/databases?tenant=" + m_Tenant, json);
m_ChromaApiClient.Post(std::format("/databases?tenant={}", m_Tenant), json);
}
catch (ChromaException& e)
{
Expand Down Expand Up @@ -115,7 +115,7 @@ namespace chromadb {

try
{
m_ChromaApiClient.Post("/collections?tenant=" + m_Tenant + "&database=" + m_Database, json);
m_ChromaApiClient.Post(std::format("/collections?tenant={}&database={}", m_Tenant, m_Database), json);
}
catch (ChromaException& e)
{
Expand All @@ -129,7 +129,7 @@ namespace chromadb {
{
try
{
auto json = m_ChromaApiClient.Get("/collections/" + name + "?tenant=" + m_Tenant + "&database=" + m_Database);
auto json = m_ChromaApiClient.Get(std::format("/collections/{}?tenant={}&database={}", name, m_Tenant, m_Database));

std::unordered_map<std::string, std::string> metadata;
if (!json["metadata"].is_null())
Expand Down Expand Up @@ -159,7 +159,7 @@ namespace chromadb {
{
try
{
auto json = m_ChromaApiClient.Get("/collections?tenant=" + m_Tenant + "&database=" + m_Database);
auto json = m_ChromaApiClient.Get(std::format("/collections?tenant={}&database={}", m_Tenant, m_Database));

std::vector<Collection> collections;
for (const auto& collection : json)
Expand All @@ -183,7 +183,7 @@ namespace chromadb {
{
try
{
return m_ChromaApiClient.Get("/count_collections?tenant=" + m_Tenant + "&database=" + m_Database);
return m_ChromaApiClient.Get(std::format("/count_collections?tenant={}&database={}", m_Tenant, m_Database));
}
catch (ChromaException& e)
{
Expand All @@ -195,7 +195,7 @@ namespace chromadb {
{
try
{
m_ChromaApiClient.Delete("/collections/" + collection.GetName() + "?tenant=" + m_Tenant + "&database=" + m_Database);
m_ChromaApiClient.Delete(std::format("/collections/{}?tenant={}&database={}", collection.GetName(), m_Tenant, m_Database));

collection.m_IsDeleted = true;
}
Expand Down Expand Up @@ -223,7 +223,7 @@ namespace chromadb {

try
{
m_ChromaApiClient.Put("/collections/" + oldCollection.GetId() + "?tenant=" + m_Tenant + "&database=" + m_Database, json);
m_ChromaApiClient.Put(std::format("/collections/{}?tenant={}?&database={}", oldCollection.GetId(), m_Tenant, m_Database), json);
}
catch (ChromaException& e)
{
Expand Down Expand Up @@ -252,7 +252,7 @@ namespace chromadb {

try
{
m_ChromaApiClient.Post("/collections/" + collection.GetId() + "/add", json);
m_ChromaApiClient.Post(std::format("/collections/{}/add", collection.GetId()), json);
}
catch (ChromaException& e)
{
Expand All @@ -279,7 +279,7 @@ namespace chromadb {

try
{
m_ChromaApiClient.Post("/collections/" + collection.GetId() + "/update", json);
m_ChromaApiClient.Post(std::format("/collections/{}/update", collection.GetId()), json);
}
catch (ChromaException& e)
{
Expand All @@ -306,7 +306,7 @@ namespace chromadb {

try
{
m_ChromaApiClient.Post("/collections/" + collection.GetId() + "/upsert", json);
m_ChromaApiClient.Post(std::format("/collections/{}/upsert", collection.GetId()), json);
}
catch (ChromaException& e)
{
Expand All @@ -318,7 +318,7 @@ namespace chromadb {
{
try
{
return m_ChromaApiClient.Get("/collections/" + collection.GetId() + "/count");
return m_ChromaApiClient.Get(std::format("/collections/{}/count", collection.GetId()));
}
catch (ChromaInvalidCollectionException& e)
{
Expand Down Expand Up @@ -346,7 +346,7 @@ namespace chromadb {

try
{
m_ChromaApiClient.Post("/collections/" + collection.GetId() + "/delete", json);
m_ChromaApiClient.Post(std::format("/collections/{}/delete", collection.GetId()), json);
}
catch (ChromaInvalidCollectionException& e)
{
Expand Down Expand Up @@ -381,7 +381,7 @@ namespace chromadb {

try
{
auto response = m_ChromaApiClient.Post("/collections/" + collection.GetId() + "/get", json);
auto response = m_ChromaApiClient.Post(std::format("/collections/{}/get", collection.GetId()), json);

std::vector<EmbeddingResource> results;
for (size_t i = 0; i < response["ids"].size(); i++)
Expand Down Expand Up @@ -418,7 +418,7 @@ namespace chromadb {
std::vector<QueryResponseResource> Client::Query(const Collection& collection, const std::vector<std::string>& queryTexts, const std::vector<std::vector<double>>& queryEmbeddings, size_t nResults, const std::vector<std::string>& include, const nlohmann::json& where_document, const nlohmann::json& where)
{
if (collection.GetIsDeleted())
throw ChromaInvalidCollectionException("Collection " + collection.GetName() + " has already been deleted");
throw ChromaInvalidCollectionException(std::format("Collection {} has already been deleted", collection.GetName()));

if (!((!queryEmbeddings.empty() && queryTexts.empty()) || (queryEmbeddings.empty() && !queryTexts.empty()) || (queryEmbeddings.empty() && queryTexts.empty())))
throw ChromaInvalidArgumentException("You must provide only one of queryEmbeddings or queryTexts");
Expand Down Expand Up @@ -457,7 +457,7 @@ namespace chromadb {

try
{
auto response = m_ChromaApiClient.Post("/collections/" + collection.GetId() + "/query", json);
auto response = m_ChromaApiClient.Post(std::format("/collections/{}/query", collection.GetId()), json);

std::vector<QueryResponseResource> queryResponses;
for (size_t i = 0; i < response["ids"].size(); i++)
Expand Down Expand Up @@ -513,7 +513,7 @@ namespace chromadb {
Client::ValidationResult Client::Validate(const Collection& collection, const std::vector<std::string>& ids, const std::vector<std::vector<double>>& embeddings, const std::vector<std::unordered_map<std::string, std::string>>& metadata, const std::vector<std::string>& documents, bool requireEmbeddingsOrDocuments)
{
if (collection.GetIsDeleted())
throw ChromaInvalidCollectionException("Collection " + collection.GetName() + " has already been deleted");
throw ChromaInvalidCollectionException(std::format("Collection {} has already been deleted", collection.GetName()));

if (requireEmbeddingsOrDocuments)
{
Expand Down Expand Up @@ -557,7 +557,7 @@ namespace chromadb {
duplicates.insert(id);
}

throw ChromaInvalidArgumentException("Expected IDs to be unique, found duplicates for: " + Utils::Join(duplicates, ", "));
throw ChromaInvalidArgumentException(std::format("Expected IDs to be unique, found duplicates for: {}", Utils::Join(duplicates, ", ")));
}

return { validatedIds, finalEmbeddings, metadata, documents };
Expand Down
2 changes: 1 addition & 1 deletion src/ChromaDB/Resources/Collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace chromadb {
void Collection::CheckDeleted() const
{
if (m_IsDeleted)
throw ChromaInvalidCollectionException("Collection " + m_Name + " has already been deleted");
throw ChromaInvalidCollectionException(std::format("Collection {} has already been deleted", m_Name));
}

} // namespace chromadb

0 comments on commit a292519

Please sign in to comment.