You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This adds required dependencies to your Gemfile, creates the initializer file `config/initializers/langchainrb_rails.rb`, database migrations to support vectorsearch, and adds the necessary code to the ActiveRecord model to enable vectorsearch.
40
40
41
41
2. Bundle && Migrate
42
42
43
-
```
44
-
bundle && rails db:migrate
43
+
```bash
44
+
bundle install && rails db:migrate
45
45
```
46
46
47
47
3. Set the env var `OPENAI_API_KEY` to your OpenAI API key.
48
48
49
49
4. Generate embeddings for your model
50
50
51
-
```
51
+
```ruby
52
52
[YOURMODEL].embed!
53
53
```
54
54
@@ -58,7 +58,7 @@ This can take a while depending on the number of database records.
58
58
59
59
### Question and Answering
60
60
61
-
```
61
+
```ruby
62
62
Product.ask("list the brands of shoes that are in stock")
63
63
```
64
64
@@ -71,7 +71,7 @@ Returns a `String` with a natural language answer. The answer is assembled using
71
71
72
72
### Similarity Search
73
73
74
-
```
74
+
```ruby
75
75
Product.similarity_search("t-shirt")
76
76
```
77
77
@@ -83,13 +83,13 @@ Returns ActiveRecord records that most closely match the `query` using Postgres
83
83
84
84
By default, embeddings are generated by calling the following within your model:
85
85
86
-
```
86
+
```ruby
87
87
to_json(except::embedding)
88
88
```
89
89
90
90
You can override this by defining an `#as_vector` method in your model:
91
91
92
-
```
92
+
```ruby
93
93
defas_vector
94
94
res = to_json(except::embedding, :owner_id, :user_id, :category_id)
0 commit comments