QdrantClient Interface
Go Testing
The QdrantClient interface allows injecting mock clients for testing without a live Qdrant instance.
Interface Definition
Section titled “Interface Definition”type QdrantClient interface { ListCollections(context.Context) ([]string, error) CollectionExists(context.Context, string) (bool, error) GetCollectionInfo(context.Context, string) (*qdrant.CollectionInfo, error) CreateCollection(context.Context, *qdrant.CreateCollection) error UpdateCollection(context.Context, *qdrant.UpdateCollection) error DeleteCollection(context.Context, string) error Upsert(context.Context, *qdrant.UpsertPoints) (*qdrant.UpdateResult, error) Query(context.Context, *qdrant.QueryPoints) ([]*qdrant.ScoredPoint, error) QueryBatch(context.Context, *qdrant.QueryBatchPoints) ([]*qdrant.BatchResult, error) QueryGroups(context.Context, *qdrant.QueryPointGroups) ([]*qdrant.PointGroup, error) Delete(context.Context, *qdrant.DeletePoints) (*qdrant.UpdateResult, error) UpdateVectors(context.Context, *qdrant.UpdatePointVectors) (*qdrant.UpdateResult, error) SetPayload(context.Context, *qdrant.SetPayloadPoints) (*qdrant.UpdateResult, error) CreateFieldIndex(context.Context, *qdrant.CreateFieldIndexCollection) (*qdrant.UpdateResult, error) Count(context.Context, *qdrant.CountPoints) (uint64, error) ScrollAndOffset(context.Context, *qdrant.ScrollPoints) ([]*qdrant.RetrievedPoint, *qdrant.PointId, error) Get(context.Context, *qdrant.GetPoints) ([]*qdrant.RetrievedPoint, error)}Creating a Real Client
Section titled “Creating a Real Client”import "github.com/srimon12/qql-go/pkg/qql"
client, err := qql.NewQdrantClient(qql.ClientConfig{ URL: "http://localhost:6334", Secret: "optional-api-key",})Mock Client for Testing
Section titled “Mock Client for Testing”Implement the interface to create test doubles:
type MockQdrantClient struct { mu sync.RWMutex collections map[string]bool points map[string][]*qdrant.ScoredPoint}
func (m *MockQdrantClient) Query(ctx context.Context, req *qdrant.QueryPoints) ([]*qdrant.ScoredPoint, error) { m.mu.RLock() defer m.mu.RUnlock() return m.points[req.CollectionName], nil}
// ... implement remaining methodsUsage:
mock := &MockQdrantClient{ points: map[string][]*qdrant.ScoredPoint{ "docs": { {Id: &qdrant.PointId{}, Payload: map[string]*qdrant.Value{"text": {Kind: &qdrant.Value_StringValue{StringValue: "hello"}}}}, }, },}
result, err := qql.Exec(ctx, mock, "QUERY 'hello' FROM docs LIMIT 5")Using with the Gateway
Section titled “Using with the Gateway”The gateway also accepts a QdrantClient implementation via server.Config:
import "github.com/srimon12/qql-go/server"
server.Run(server.Config{ ListenAddr: ":50051", QdrantURL: "http://localhost:6334", QQLConfig: &config.Config{InferenceMode: "cloud"},})