Skip to content
Merged
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.git
build/
node_modules/
docs/
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/build_release_aws_x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build Pre-build Packages for AWS

on:
workflow_dispatch:
push:
tags:
- "*"

concurrency:
group: release
cancel-in-progress: false

jobs:
build:
environment: release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
submodules: "true"
- name: Setup Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
- name: NPM Pack
run: npm pack
- name: Rename Package
run: mv faiss-node-*.tgz faiss-node.tgz
- name: Build & test
run: docker build -f Dockerfile.buildaws -t faiss-build-aws .
- name: Get Version
id: version
run: |
VERSION=$(node -p -e "require('./package.json').version")
echo $VERSION
echo VERSION=$VERSION >> "$GITHUB_OUTPUT"
- name: Package
run: |
tempid=$(docker create faiss-build-aws)
docker cp $tempid:/var/task aws
docker rm -v $tempid
cd aws && ls -laht
mkdir nodejs && mv node_modules nodejs/node_modules && ln -s nodejs/node_modules node_modules
zip -r --symlinks faiss-node-v${{ steps.version.outputs.VERSION }}-aws-x64.zip .
- name: Upload to Release
uses: softprops/action-gh-release@v1
with:
draft: true
fail_on_unmatched_files: true
files: aws/*.zip
tag_name: "v${{ steps.version.outputs.VERSION }}"
29 changes: 29 additions & 0 deletions Dockerfile.buildaws
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM public.ecr.aws/lambda/nodejs:18 as build
COPY package*.json ./
RUN npm ci --ignore-scripts

RUN yum -y install wget tar gzip gcc gcc-c++ make lapack-devel patchelf
RUN wget -q https://github.com/Kitware/CMake/releases/download/v3.27.0/cmake-3.27.0-linux-x86_64.sh && \
sh cmake-3.27.0-linux-x86_64.sh --skip-license --exclude-subdir --prefix=/usr/local

RUN patchelf --set-rpath "\$ORIGIN/" /lib64/libgfortran.so.4

ENTRYPOINT ["tail"]
CMD ["-f","/dev/null"]
COPY . .
RUN npm run build:test


FROM public.ecr.aws/lambda/nodejs:18
COPY faiss-node.tgz ./
RUN npm init -y && npm i faiss-node.tgz --ignore-scripts && rm faiss-node.tgz
COPY examples/index-aws.js index.js
COPY --from=build /var/task/build/Release/faiss-node.node node_modules/faiss-node/build/Release/faiss-node.node
COPY --from=build /var/task/build/Release/libfaiss.a node_modules/faiss-node/build/Release/libfaiss.a
COPY --from=build /lib64/libgomp.so.1 node_modules/faiss-node/build/Release/libgomp.so.1
COPY --from=build /lib64/libpthread.so.0 node_modules/faiss-node/build/Release/libpthread.so.0
COPY --from=build /lib64/libblas.so.3 node_modules/faiss-node/build/Release/libblas.so.3
COPY --from=build /lib64/liblapack.so.3 node_modules/faiss-node/build/Release/liblapack.so.3
COPY --from=build /lib64/libgfortran.so.4 node_modules/faiss-node/build/Release/libgfortran.so.4
COPY --from=build /lib64/libquadmath.so.0 node_modules/faiss-node/build/Release/libquadmath.so.0
RUN node index.js
12 changes: 12 additions & 0 deletions Dockerfile.debugaws
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM public.ecr.aws/lambda/nodejs:18
COPY package*.json ./
RUN npm ci --ignore-scripts

RUN yum -y install wget tar gzip gcc gcc-c++ make lapack-devel
RUN wget -q https://github.com/Kitware/CMake/releases/download/v3.27.0/cmake-3.27.0-linux-x86_64.sh && \
sh cmake-3.27.0-linux-x86_64.sh --skip-license --exclude-subdir --prefix=/usr/local

COPY . .

ENTRYPOINT ["tail"]
CMD ["-f","/dev/null"]
22 changes: 22 additions & 0 deletions examples/index-aws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { IndexFlatL2 } = require('faiss-node');

exports.handler = async function(event, context) {
const dimension = 2;
const index = new IndexFlatL2(dimension);

console.log(index.getDimension());
console.log(index.isTrained());
console.log(index.ntotal());
index.add([1, 0]);
index.add([1, 2]);
index.add([1, 3]);
index.add([1, 1]);
console.log(index.ntotal());

const k = 4;
const results = index.search([1, 0], k);
console.log(results.labels);
console.log(results.distances);

return results;
};
2 changes: 1 addition & 1 deletion examples/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { IndexFlatL2 } = require('../lib/index');
const { IndexFlatL2 } = require('faiss-node');

const dimension = 2;
const index = new IndexFlatL2(dimension);
Expand Down