Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds GenAI client object #1

Merged
merged 23 commits into from
Mar 4, 2024
Merged

Adds GenAI client object #1

merged 23 commits into from
Mar 4, 2024

Conversation

willtai
Copy link
Contributor

@willtai willtai commented Feb 29, 2024

Description

Adds GenAIClient to create indexes, drops indexes, and perform similarity search on a Neo4j database. Also contains pre-commit configuration.

Checklist

  • Create client
  • Create index method
  • Database query method
  • Drop index method
  • Similarity search for vector method
  • Similarity search for text method
  • Error handling
  • Configure pre-commit-config Handled in Jonbesga/tests #2
  • Write README

Testing

neo4j_genai_python/src/client.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
List[Dict[str, Any]]: List of dictionaries containing the query results.
"""
params = params or {}
with driver.session() as session:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the proper usage for the driver? I have seen in other places where the database needs to be passed to session e.g.

with driver.session(database="neo4j") as session:

Is this necessarily the case?

neo4j_genai/src/client.py Outdated Show resolved Hide resolved
neo4j_genai/src/client.py Outdated Show resolved Hide resolved
neo4j_genai/src/embeddings.py Outdated Show resolved Hide resolved
neo4j_genai/src/data_validators.py Outdated Show resolved Hide resolved
List[Dict[str, Any]]: List of dictionaries containing the query results.
"""
params = params or {}
with driver.session() as session:
Copy link
Contributor

Choose a reason for hiding this comment

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

You are passing the driver all around the code. Why not just set it in the __init__ and do with self.driver.session() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we initially decided this during the design phase so that it is more explicit, right? I do think setting in __init__ is more readable and Pythonic though. I would prefer to do it like you suggested here

@willtai
Copy link
Contributor Author

willtai commented Mar 1, 2024

@jonbesga Oskar and I discussed earlier today that we want to add this behaviour for allowing users to give more "advanced" queries where they also pass in a Cypher query string as seen in:

I don't think this should be part of this PR, but I think it's good to include this in the first version of this package, what do you think?

@jonbesga
Copy link
Contributor

jonbesga commented Mar 1, 2024

@jonbesga Oskar and I discussed earlier today that we want to add this behaviour for allowing users to give more "advanced" queries where they also pass in a Cypher query string as seen in:

I don't think this should be part of this PR, but I think it's good to include this in the first version of this package, what do you think?

I'm confused what behaviour are your referring to😅

@willtai willtai marked this pull request as ready for review March 4, 2024 09:38
@root_validator(pre=True)
def check_query(cls, values):
query_vector, query_text = values.get("query_vector"), values.get("query_text")
if bool(query_vector) ^ bool(query_text):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ^ operator only works with booleans

@jonbesga
Copy link
Contributor

jonbesga commented Mar 4, 2024

Can you squash all the commits into one?

@willtai
Copy link
Contributor Author

willtai commented Mar 4, 2024

Can you squash all the commits into one?

I've now set the default for merging PRs to be 'Squash and merge', so on the base branch it will be squashed

@jonbesga jonbesga self-requested a review March 4, 2024 14:01
name: str
label: str
property: str
dimensions: int = Field(ge=1, le=2048)
Copy link
Contributor Author

@willtai willtai Mar 4, 2024

Choose a reason for hiding this comment

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

This will change to 4096 in the next neo4j v5.18 release, so we will need to make this change in future

Validates that one of either query_vector or query_text is provided exclusively.
"""
query_vector, query_text = values.get("query_vector"), values.get("query_text")
if not (bool(query_vector) ^ bool(query_text)):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ^ Python operator only works for booleans

@willtai willtai merged commit 7f27093 into main Mar 4, 2024
@willtai willtai deleted the add-genai-client branch March 4, 2024 17:00
def __init__(
self,
driver: Driver,
embeddings: Optional[Embeddings] = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider embedding instead of embeddings? This could be confusing because it could mean embedding the noun instead of the verb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Embedder as seen in haystack

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both class and argument

Returns:
List[Dict[str, Any]]: List of dictionaries containing the query results.
"""
with self.driver.session() as session:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants