Skip to content

[Backend] Implement Supabase RPC for Finding Related Snippets #223

@nhphong

Description

@nhphong

Develop a Remote Procedure Call (RPC) in Supabase to find related snippets based on cosine similarity. This RPC should take a snippet ID as input and return a list of related snippets, excluding the original snippet itself.

Requirements:

  • Utilize the pre-existing vector embeddings for all snippets to compute cosine similarity.
  • Implement a function that calculates the cosine similarity between the given snippet's vector and all other snippets' vectors.
  • Ensure that the related snippets returned do not include the snippet corresponding to the provided ID.
  • Optimize the RPC for performance and scalability, considering the potential size of data.

Acceptance Criteria:

  1. Input: The RPC accepts a single input, which is the snippet ID.
  2. Output: The RPC returns a list of snippet IDs that are most similar to the given snippet, based on cosine similarity.
  3. Exclusion: The list of related snippets must not include the original snippet ID.
  4. Accuracy: The cosine similarity calculation must correctly identify related snippets.
  5. Performance: The RPC should execute efficiently, providing results within an acceptable timeframe for large datasets.

Testing:

  • Verify that the RPC correctly identifies and returns related snippets for a given snippet ID.
  • Confirm that the original snippet is not included in the results.
  • Test the RPC with various snippet IDs to ensure consistent performance and accuracy.

Notes:

  • Ensure that the solution is well-documented, with clear instructions on how to invoke the RPC.
  • Consider edge cases, such as when a snippet has no related snippets.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions