Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions faiss/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
#define FAISS_VERSION_MINOR 8
#define FAISS_VERSION_PATCH 0

// Macro to combine the version components into a single string
#ifndef FAISS_STRINGIFY
#define FAISS_STRINGIFY(ARG) #ARG
#endif
#ifndef FAISS_TOSTRING
#define FAISS_TOSTRING(ARG) FAISS_STRINGIFY(ARG)
#endif
#define VERSION_STRING \
FAISS_TOSTRING(FAISS_VERSION_MAJOR) \
"." FAISS_TOSTRING(FAISS_VERSION_MINOR) "." FAISS_TOSTRING( \
FAISS_VERSION_PATCH)

/**
* @namespace faiss
*
Expand All @@ -38,8 +50,8 @@

namespace faiss {

/// Forward declarations see impl/AuxIndexStructures.h, impl/IDSelector.h and
/// impl/DistanceComputer.h
/// Forward declarations see impl/AuxIndexStructures.h, impl/IDSelector.h
/// and impl/DistanceComputer.h
struct IDSelector;
struct RangeSearchResult;
struct DistanceComputer;
Expand All @@ -56,7 +68,8 @@ struct SearchParameters {
virtual ~SearchParameters() {}
};

/** Abstract structure for an index, supports adding vectors and searching them.
/** Abstract structure for an index, supports adding vectors and searching
* them.
*
* All vectors provided at add or search time are 32-bit float arrays,
* although the internal representation may vary.
Expand Down Expand Up @@ -154,7 +167,8 @@ struct Index {

/** return the indexes of the k vectors closest to the query x.
*
* This function is identical as search but only return labels of neighbors.
* This function is identical as search but only return labels of
* neighbors.
* @param n number of vectors
* @param x input vectors to search, size n * d
* @param labels output labels of the NNs, size n*k
Expand All @@ -179,7 +193,8 @@ struct Index {
*/
virtual void reconstruct(idx_t key, float* recons) const;

/** Reconstruct several stored vectors (or an approximation if lossy coding)
/** Reconstruct several stored vectors (or an approximation if lossy
* coding)
*
* this function may not be defined for some indexes
* @param n number of vectors to reconstruct
Expand Down
5 changes: 5 additions & 0 deletions faiss/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

// -*- c++ -*-

#include <faiss/Index.h>
#include <faiss/utils/utils.h>

#include <cassert>
Expand Down Expand Up @@ -129,6 +130,10 @@ std::string get_compile_options() {
return options;
}

std::string get_version() {
return VERSION_STRING;
}

#ifdef _MSC_VER
double getmillisecs() {
LARGE_INTEGER ts;
Expand Down
3 changes: 3 additions & 0 deletions faiss/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ std::string get_compile_options();
* Get some stats about the system
**************************************************/

// Expose FAISS version as a string
std::string get_version();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a bit of a waste to produce an allocated string that is already known at compile time. It also does not contribute to exposing this version to the C API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also does not contribute to exposing this version to the C API

I am not sure I understand, can you explain?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string get_version() is not a function signature compatible with C due to the C++ string type.

Ultimately, this PR claims to extend the C API while not touching the C API at all. :)


/// ms elapsed since some arbitrary epoch
double getmillisecs();

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(FAISS_TEST_SRC
test_disable_pq_sdc_tables.cpp
test_common_ivf_empty_index.cpp
test_callback.cpp
test_utils.cpp
)

add_executable(faiss_test ${FAISS_TEST_SRC})
Expand Down
19 changes: 19 additions & 0 deletions tests/test_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <gtest/gtest.h>

#include <faiss/Index.h>
#include <faiss/utils/utils.h>

TEST(TestUtils, get_version) {
std::string version = std::to_string(FAISS_VERSION_MAJOR) + "." +
std::to_string(FAISS_VERSION_MINOR) + "." +
std::to_string(FAISS_VERSION_PATCH);

EXPECT_EQ(version, faiss::get_version());
}