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

Apply Strategy pattern to Embeddings #137

Closed
JdFSilva opened this issue Nov 4, 2024 · 0 comments
Closed

Apply Strategy pattern to Embeddings #137

JdFSilva opened this issue Nov 4, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@JdFSilva
Copy link
Contributor

JdFSilva commented Nov 4, 2024

strategy design pattern

Rough example:

from abc import ABC


class EmbeddingsBase(ABC):
    def find_similar_embeddings(self, query_params):
        query = (
            select(
                Embedding,
                Embedding.embedding.cosine_distance(query_params).label("distance"),
            )
            .where(Embedding.embedding.cosine_distance(query_params) < similarity_threshold)
            .order_by("distance")
            .limit(10)
        )
        return connection.execute(query).fetchall()

    def x(self):
        return NotImplemented

class EmbeddingsOpenAI(EmbeddingsBase):
    def x(self):
        self.find_similar_embeddings("A")
        return "O"

class EmbeddingsOllamaAPI(EmbeddingsBase):
    def x(self):
        return "A"
    
class EmbeddingsOllamaLocal(EmbeddingsBase):
    def __init__(self, **kwargs):
        print(kwargs)
    
    def x(self):
        return "MA"

class Embeddings:
    def __init__(self, embeddings, **kwargs):
        self.embeddings = embeddings(**kwargs)

    def x(self):
        return self.embeddings.x()
    

Embeddings(embeddings=EmbeddingsOllamaLocal, foo="lama").x()
@JdFSilva JdFSilva added the enhancement New feature or request label Nov 4, 2024
@jfrverdasca jfrverdasca mentioned this issue Nov 6, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants