Skip to content

Commit

Permalink
Added comment about Embedder type in docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
willtai committed Apr 22, 2024
1 parent 2a21e0d commit e6b43dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/similarity_search_for_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from random import random
from neo4j_genai.embedder import Embedder
from neo4j_genai.indexes import create_vector_index, drop_index
from neo4j_genai.indexes import create_vector_index

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


# Create Embedder object
# Create CustomEmbedder object with the required Embedder type
class CustomEmbedder(Embedder):
def embed_query(self, text: str) -> list[float]:
return [random() for _ in range(DIMENSION)]
Expand Down Expand Up @@ -52,4 +52,4 @@ def embed_query(self, text: str) -> list[float]:

# Perform the similarity search for a text query
query_text = "hello world"
# print(retriever.search(query_text=query_text, top_k=5))
print(retriever.search(query_text=query_text, top_k=5))
16 changes: 4 additions & 12 deletions src/neo4j_genai/retrievers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def search(self, *args, **kwargs) -> Any:

class VectorRetriever(Retriever):
"""
Provides retrieval method using vector search over embeddings
Provides retrieval method using vector search over embeddings.
If an embedder is provided, it needs to have the required Embedder type.
"""

def __init__(
Expand All @@ -80,11 +81,6 @@ def __init__(
self._verify_version()
self.index_name = index_name
self.return_properties = return_properties

if embedder and not isinstance(embedder, Embedder):
raise TypeError(
"Provided 'embedder' must be an instance of Embedder with an 'embed_query' method."
)
self.embedder = embedder

def search(
Expand Down Expand Up @@ -160,7 +156,8 @@ def search(

class VectorCypherRetriever(Retriever):
"""
Provides retrieval method using vector similarity and custom Cypher query
Provides retrieval method using vector similarity and custom Cypher query.
If an embedder is provided, it needs to have the required Embedder type.
"""

def __init__(
Expand All @@ -174,11 +171,6 @@ def __init__(
self._verify_version()
self.index_name = index_name
self.retrieval_query = retrieval_query

if embedder and not isinstance(embedder, Embedder):
raise TypeError(
"Provided 'embedder' must be an instance of Embedder with an 'embed_query' method."
)
self.embedder = embedder

def search(
Expand Down

0 comments on commit e6b43dd

Please sign in to comment.