/

hasura-header-illustration

Instant GraphQL APIs on Qdrant

In the modern era of artificial intelligence, one of the most important capabilities exploding in popularity is the ability to perform semantic searches on data.

These searches, more technically known as “vector search” are increasingly important in retrieval augmented generation (RAG) workflows. They also provide a way to “ground” an LLM with source knowledge, which can help reduce hallucinations and improve accuracy.

Today we are excited to announce that performing a vector search has never been easier with the release of the new Hasura Qdrant connector.

To try it out yourself, get started with Hasura DDN here. The steps for working with the Qdrant connector can be found in this GitHub repository.

What can the Hasura Qdrant connector do?

The Hasura Qdrant Connector can connect to a Qdrant database, introspect the underlying data, and expose a GraphQL API with both queries and mutations for the database.

What capabilities does the Hasura Qdrant connector have?

The Hasura Qdrant connector comes with a handful of capabilities out of the box. Here are some of the types of queries that are currently supported.

Simple queries:

query Query {
  qdrant_album(args: {}) {
    albumId
    artistId
    title
  }
}

Queries with predicates:

query Query {
  simple_predicate: qdrant_album(args: {}, where: {albumId: {eq: 10}}) {
    albumId
    artistId
    title
  }
  and_predicate: qdrant_album(
    args: {}
    where: {_and: {albumId: {gt: 300}, title: {like: "Great"}}}
  ) {
    albumId
    artistId
    title
  }
}

Queries with vector search:

query Query($vector: [Float!]!) {
  qdrant_album(
    args: {search: {name: "fast-bge-small-en", vector: $vector}}
  ) {
    albumId
    artistId
    title
    score
  }
}

Queries with vector search and predicate filtering:

query Query($vector: [Float!]!) {
  qdrant_album(
    args: {search: {name: "fast-bge-small-en", vector: $vector}}
    where: {title: {like: "Great"}}
  ) {
    albumId
    artistId
    title
    score
  }
}

Queries with recommendation search:

query Query {
  qdrant_album(
    args: {recommend: {using: "fast-bge-small-en", positive: ["0172927f-2b0d-452d-a7cd-94bbdcde0750"], negative: ["00105150-3bf7-4f43-9f6f-d378fd05b3e4"]}}
  ) {
    albumId
    artistId
    title
  }
}

The Qdrant connector also has support for performing mutations. Here are some of the mutations that are currently supported.

Insert mutations:

mutation Mutation($vectors: [[Float!]!]!) {
  qdrant_insertAlbumOne(
    object: {id: "0172927f-2b0d-452d-a7cd-94bbdcde0758", vectorNames: ["fast-bge-small-en"], vectors: $vectors, albumId: 1000, artistId: 10, title: "New Album"}
  )
}

Update mutations:

mutation Mutation($vectors: [[Float!]!]!) {
  qdrant_updateAlbumOne(
    object: {id: "0172927f-2b0d-452d-a7cd-94bbdcde0758", vectorNames: ["fast-bge-small-en"], vectors: $vectors, albumId: 1000, artistId: 10, title: "New Album 2"}
  )
}

Delete mutations:

mutation Mutation {
  qdrant_deleteAlbumOne(id: "0172927f-2b0d-452d-a7cd-94bbdcde0758")
}

These queries and mutations are useful on their own, but the most powerful feature of the Qdrant connector is the ability of the Hasura GraphQL Engine to allow for the creation of relationships between Qdrant and other data-sources, such as PostgreSQL for example.

This powerful feature allows you to perform a vector or recommendation search, and then join the resulting data back to your PostgreSQL database.

query Query {
  qdrant_album(
    args: {recommend: {using: "fast-bge-small-en", positive: ["0172927f-2b0d-452d-a7cd-94bbdcde0750"], negative: ["00105150-3bf7-4f43-9f6f-d378fd05b3e4"]}}
    limit: 10
  ) {
    albumId
    postgresAlbum {
      albumId
      artistId
      title
    }
  }
}

Conclusion

The Hasura Qdrant connector is a powerful tool for developers looking to harness the power of GraphQL for vector and recommendation search on their data. One of the most compelling use cases for the Qdrant connector is its role in Retrieval-Augmented Generation (RAG) workflows.

By enabling vector search, the connector allows for semantic searches that enhance the accuracy and relevance of information retrieved by AI models.

Try it out yourself by getting started with Hasura DDN here. The steps for working with the Qdrant connector can be found in this GitHub repository.

Blog
03 Jul, 2024
Email
Subscribe to stay up-to-date on all things Hasura. One newsletter, once a month.
Loading...
v3-pattern
Accelerate development and data access with radically reduced complexity.