Skip to content

Commit 8895320

Browse files
committed
Updated examples to use Informers [skip ci]
1 parent 3c0134f commit 8895320

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Or check out some examples:
2525

2626
- [Embeddings](examples/openai_embeddings.rb) with OpenAI
2727
- [Binary embeddings](examples/cohere_embeddings.rb) with Cohere
28-
- [Sentence embeddings](examples/sentence_embeddings.rb) with Transformers.rb
29-
- [Hybrid search](examples/hybrid_search.rb) with Transformers.rb (Reciprocal Rank Fusion)
28+
- [Sentence embeddings](examples/sentence_embeddings.rb) with Informers
29+
- [Hybrid search](examples/hybrid_search.rb) with Informers (Reciprocal Rank Fusion)
3030
- [Sparse search](examples/sparse_search.rb) with Transformers.rb
3131
- [Morgan fingerprints](examples/morgan_fingerprints.rb) with RDKit.rb
3232
- [Topic modeling](examples/topic_modeling.rb) with tomoto.rb

examples/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ source "https://rubygems.org"
33
gemspec path: ".."
44

55
gem "disco"
6+
gem "informers", ">= 1"
67
gem "numo-narray"
78
gem "pg"
89
gem "rdkit-rb"

examples/hybrid_search.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
require "informers"
12
require "pg"
23
require "pgvector"
3-
require "transformers-rb"
44

55
conn = PG.connect(dbname: "pgvector_example")
66
conn.exec("CREATE EXTENSION IF NOT EXISTS vector")
@@ -9,14 +9,14 @@
99
conn.exec("CREATE TABLE documents (id bigserial PRIMARY KEY, content text, embedding vector(384))")
1010
conn.exec("CREATE INDEX ON documents USING GIN (to_tsvector('english', content))")
1111

12-
model = Transformers::SentenceTransformer.new("sentence-transformers/multi-qa-MiniLM-L6-cos-v1")
12+
model = Informers::Model.new("Xenova/multi-qa-MiniLM-L6-cos-v1")
1313

1414
input = [
1515
"The dog is barking",
1616
"The cat is purring",
1717
"The bear is growling"
1818
]
19-
embeddings = model.encode(input)
19+
embeddings = model.embed(input)
2020
input.zip(embeddings) do |content, embedding|
2121
conn.exec_params("INSERT INTO documents (content, embedding) VALUES ($1, $2)", [content, embedding])
2222
end
@@ -45,7 +45,7 @@
4545
LIMIT 5
4646
SQL
4747
query = "growling bear"
48-
query_embedding = model.encode(query)
48+
query_embedding = model.embed(query)
4949
k = 60
5050
result = conn.exec_params(sql, [query, query_embedding, k])
5151
result.each do |row|

examples/sentence_embeddings.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1+
require "informers"
12
require "pg"
23
require "pgvector"
3-
require "transformers-rb"
44

55
conn = PG.connect(dbname: "pgvector_example")
66
conn.exec("CREATE EXTENSION IF NOT EXISTS vector")
77

88
conn.exec("DROP TABLE IF EXISTS documents")
99
conn.exec("CREATE TABLE documents (id bigserial PRIMARY KEY, content text, embedding vector(384))")
1010

11-
model = Transformers::SentenceTransformer.new("sentence-transformers/all-MiniLM-L6-v2")
11+
model = Informers::Model.new("sentence-transformers/all-MiniLM-L6-v2")
1212

1313
input = [
1414
"The dog is barking",
1515
"The cat is purring",
1616
"The bear is growling"
1717
]
18-
embeddings = model.encode(input)
18+
embeddings = model.embed(input)
1919

2020
input.zip(embeddings) do |content, embedding|
2121
conn.exec_params("INSERT INTO documents (content, embedding) VALUES ($1, $2)", [content, embedding])

0 commit comments

Comments
 (0)