Class: TurboRAG::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/turborag.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_url, timeout: 30) ⇒ Client

Returns a new instance of Client.

Parameters:

  • base_url (String)

    TurboRAG server URL (e.g. “localhost:8080”)

  • timeout (Integer) (defaults to: 30)

    request timeout in seconds (default: 30)



28
29
30
31
# File 'lib/turborag.rb', line 28

def initialize(base_url, timeout: 30)
  @base_uri = URI.parse(base_url.chomp("/"))
  @timeout = timeout
end

Instance Method Details

#healthHash

Health check.

Returns:

  • (Hash)


78
79
80
# File 'lib/turborag.rb', line 78

def health
  get("/health")
end

#indexHash

Index configuration and stats.

Returns:

  • (Hash)


84
85
86
# File 'lib/turborag.rb', line 84

def index
  get("/index")
end

#ingest(records:) ⇒ Hash

Add records with precomputed embeddings.

Parameters:

  • records (Array<Hash>)

    each with :chunk_id, :text, :embedding

Returns:

  • (Hash)


64
65
66
# File 'lib/turborag.rb', line 64

def ingest(records:)
  post("/ingest", { records: records })
end

#ingest_text(text:, source_doc: nil) ⇒ Hash

Ingest raw text with auto-chunking (requires –model).

Parameters:

  • text (String)
  • source_doc (String, nil) (defaults to: nil)

Returns:

  • (Hash)


72
73
74
# File 'lib/turborag.rb', line 72

def ingest_text(text:, source_doc: nil)
  post("/ingest-text", { text: text, source_doc: source_doc })
end

#metricsHash

Latency and error metrics.

Returns:

  • (Hash)


90
91
92
# File 'lib/turborag.rb', line 90

def metrics
  get("/metrics")
end

#query(vector:, top_k: 5) ⇒ Hash

Search by embedding vector.

Parameters:

  • vector (Array<Float>)
  • top_k (Integer) (defaults to: 5)

Returns:

  • (Hash)

    { “count” => N, “results” => […] }



37
38
39
# File 'lib/turborag.rb', line 37

def query(vector:, top_k: 5)
  post("/query", { query_vector: vector, top_k: top_k })
end

#query_batch(queries:, top_k: 5) ⇒ Hash

Batch vector search.

Parameters:

  • queries (Array<Hash>)

    each with :vector key

  • top_k (Integer) (defaults to: 5)

Returns:

  • (Hash)


53
54
55
56
57
58
59
# File 'lib/turborag.rb', line 53

def query_batch(queries:, top_k: 5)
  payload = {
    queries: queries.map { |q| { query_vector: q[:vector] } },
    top_k: top_k,
  }
  post("/query/batch", payload)
end

#query_text(text:, top_k: 5) ⇒ Hash

Search by text (requires –model on the server).

Parameters:

  • text (String)
  • top_k (Integer) (defaults to: 5)

Returns:

  • (Hash)


45
46
47
# File 'lib/turborag.rb', line 45

def query_text(text:, top_k: 5)
  post("/query", { query_text: text, top_k: top_k })
end