Skip to content

Commit

Permalink
Jonbesga/tests (#2)
Browse files Browse the repository at this point in the history
* Update Github Actions and resolve merge conflicts

* Fixed conflicts and lock dependencies

relock dependencies

Linting with ruff

fixed linting issues

* Adds tests for similarity search

* Changed test to mock neo4j driver's execute_driver instead of the client's _database_query()

Changed test_client.py to have mocks at execute_query level

Changed precommit config to include ruff linting and formatting

Update pre-commit

Corrected cypher query error test and dimensions constraint in CreateIndexModel data type

ruff formatting

remove drop index in example

* Add pypi publishing workflow

* Remove database_query method and use execute_query

* Add validation error test

* Remove exclude property from pyproject.toml

* Bump version and lint

---------

Co-authored-by: Will Tai <[email protected]>
  • Loading branch information
jonbesga and willtai authored Mar 19, 2024
1 parent 7f27093 commit a212d89
Show file tree
Hide file tree
Showing 15 changed files with 732 additions and 174 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8
max_line_length = 88
34 changes: 34 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: neo4j_genai PR
on: pull_request

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install root project
run: poetry install --no-interaction
- name: Check format and linting
run: |
poetry run ruff format --check .
poetry run ruff check .
- name: Run tests and check coverage
run: |
poetry run coverage run -m pytest
poetry run coverage report --fail-under=85
72 changes: 72 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Publish Python 🐍 distribution 📦

on: push

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: PyPI
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/neo4j-genai
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

publish-to-testpypi:
name: TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/neo4j-genai

permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
dist/
**/__pycache__/*
*.py[cod]
.mypy_cache/
.mypy_cache/
.coverage
htmlcov/
.idea/
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0 # Use the ref you want to point at
rev: v4.5.0
hooks:
- id: trailing-whitespace
# - id: ...
- id: end-of-file-fixer
13 changes: 6 additions & 7 deletions examples/similarity_search_for_text.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import List
from neo4j import GraphDatabase
from neo4j.exceptions import DatabaseError
from neo4j_genai.client import GenAIClient

from random import random
from neo4j_genai.embeddings import Embeddings
from neo4j_genai.embedder import Embedder

URI = "neo4j://localhost:7687"
AUTH = ("neo4j", "password")
Expand All @@ -16,16 +15,16 @@
driver = GraphDatabase.driver(URI, auth=AUTH)


# Create Embeddings object
class CustomEmbeddings(Embeddings):
# Create Embedder object
class CustomEmbedder(Embedder):
def embed_query(self, text: str) -> List[float]:
return [random() for _ in range(DIMENSION)]


embeddings = CustomEmbeddings()
embedder = CustomEmbedder()

# Initialize the client
client = GenAIClient(driver, embeddings)
client = GenAIClient(driver, embedder)

# Creating the index
client.create_index(
Expand All @@ -47,7 +46,7 @@ def embed_query(self, text: str) -> List[float]:
parameters = {
"vector": vector,
}
client.database_query(insert_query, params=parameters)
driver.execute_query(insert_query, parameters)

# Perform the similarity search for a text query
query_text = "hello world"
Expand Down
3 changes: 2 additions & 1 deletion examples/similarity_search_for_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
parameters = {
"vector": vector,
}
client.database_query(insert_query, params=parameters)

driver.execute_query(insert_query, parameters)

# Perform the similarity search for a vector query
query_vector = [random() for _ in range(DIMENSION)]
Expand Down
Loading

0 comments on commit a212d89

Please sign in to comment.