Skip to content

Commit

Permalink
collection docs (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
emrgnt-cmplxty authored Aug 23, 2024
1 parent b5c3db0 commit 7b1d406
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion py/core/base/abstractions/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def dict(self) -> dict:
if self.vector_search_results
else []
),
"kg_search_results": self.kg_search_results or [],
"kg_search_results": self.kg_search_results or None,
}


Expand Down
2 changes: 1 addition & 1 deletion py/core/base/providers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def register(self, email: str, password: str) -> Dict[str, str]:
pass

@abstractmethod
def verify_email(self, verification_code: str) -> Dict[str, str]:
def verify_email(self, email: str, verification_code: str) -> Dict[str, str]:
pass

@abstractmethod
Expand Down
3 changes: 2 additions & 1 deletion py/core/main/api/routes/auth/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async def register_app(
)
@self.base_endpoint
async def verify_email_app(
email: EmailStr = Body(..., description="User's email address"),
verification_code: str = Body(
..., description="Email verification code"
)
Expand All @@ -55,7 +56,7 @@ async def verify_email_app(
This endpoint is used to confirm a user's email address using the verification code
sent to their email after registration.
"""
result = await self.engine.averify_email(verification_code)
result = await self.engine.averify_email(email, verification_code)
return GenericMessageResponse(message=result["message"])

@self.router.post("/login", response_model=WrappedTokenResponse)
Expand Down
2 changes: 1 addition & 1 deletion py/core/main/api/routes/retrieval/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def search_app(
description=search_descriptions.get("kg_search_settings"),
),
auth_user=Depends(self.engine.providers.auth.auth_wrapper),
) -> WrappedSearchResponse:
) -> WrappedSearchResponse:
"""
Perform a search query on the vector database and knowledge graph.
Expand Down
8 changes: 7 additions & 1 deletion py/core/main/services/auth_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def register(self, email: str, password: str) -> UserResponse:
return self.providers.auth.register(email, password)

@telemetry_event("VerifyEmail")
async def verify_email(self, verification_code: str) -> bool:
async def verify_email(self, email: str, verification_code: str) -> bool:

if not self.config.auth.require_email_verification:
raise R2RException(
Expand All @@ -49,6 +49,12 @@ async def verify_email(self, verification_code: str) -> bool:
raise R2RException(
status_code=400, message="Invalid or expired verification code"
)

user = self.providers.database.relational.get_user_by_id(user_id)
if not user or user.email != email:
raise R2RException(
status_code=400, message="Invalid or expired verification code"
)

self.providers.database.relational.mark_user_as_verified(user_id)
self.providers.database.relational.remove_verification_code(
Expand Down
6 changes: 3 additions & 3 deletions py/core/providers/database/vecs/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def _create(self):
tsvector_update_trigger(fts, 'pg_catalog.english', text);
"""
)
)
)
return self

def _drop(self):
Expand Down Expand Up @@ -1168,12 +1168,12 @@ def _build_table(name: str, meta: MetaData, dimension: int) -> Table:
extend_existing=True,
)

# Add GIN index for full-text search and trigram similarity
# # Add GIN index for full-text search and trigram similarity
Index(
f"idx_{name}_fts_trgm",
table.c.fts,
table.c.text,
postgresql_using="gin",
postgresql_ops={"text": "gin_trgm_ops"}, # Remove gin_tsvector_ops
postgresql_ops={"text": "gin_trgm_ops"}, # alternative, gin_tsvector_ops
)
return table
5 changes: 1 addition & 4 deletions py/core/providers/database/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ def _initialize_vector_db(self, dimension: int) -> None:
self.collection = self.vx.get_or_create_collection(
name=self.collection_name, dimension=dimension
)
self.collection.create_index(measure="cosine_distance")
self.collection.create_index(measure="l2_distance")
self.collection.create_index(measure="max_inner_product")


def upsert(self, entry: VectorEntry) -> None:
if self.collection is None:
raise ValueError(
Expand Down

0 comments on commit 7b1d406

Please sign in to comment.