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

database collection crud endpoints #16

Closed
Rusteam opened this issue May 13, 2024 · 3 comments
Closed

database collection crud endpoints #16

Rusteam opened this issue May 13, 2024 · 3 comments

Comments

@Rusteam
Copy link
Contributor

Rusteam commented May 13, 2024

We're using hayhooks to serve haystack pipelines and we need a way to find out which collections are already present in the vector db (qdrant). We've decided to build a custom component and deploy it, however I wonder if it's better to create these methods for fastapi by default?

@Rusteam Rusteam changed the title database database collection crud endpoints May 13, 2024
@masci
Copy link
Contributor

masci commented May 13, 2024

That's a good one - I would have done the same, custom component wrapped in a pipeline that's just there for the purpose of invoking that component.

But the line between a clever use of hayooks' design and a hack is blurry here, I wonder if we should support explicitly the customization of the internal FastAPI router...

@Rusteam
Copy link
Contributor Author

Rusteam commented May 14, 2024

the component turned out to be quite simple:


@component
class QdrantCollectionManagement(DocumentWriter):
    def __init__(
        self,
        document_store: QdrantDocumentStoreExt,
        policy: DuplicatePolicy = DuplicatePolicy.NONE,
    ):
        self.document_store = document_store
        self.client = document_store.client
        self.index = document_store.index
        self.policy = policy

    @component.output_types(collections=list[str])
    def run(self, action: str):
        action = QdrantCollectionAction(action)
        if action == QdrantCollectionAction.delete:
            self.client.delete_collection(self.index)
        collections = list(
            map(lambda x: x.name, self.client.get_collections().collections)
        )
        return {"collections": collections}

alternatively, I could commit it to qdrant integrations for re-usage

@masci
Copy link
Contributor

masci commented May 15, 2024

That's great @Rusteam! Please tag me if you contribute the component to the integration, I can review!

@Rusteam Rusteam closed this as completed May 17, 2024
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

No branches or pull requests

2 participants