Skip to content

Commit

Permalink
Add k to pinecone's "ask" functionality (#297)
Browse files Browse the repository at this point in the history
* update specs to allow for k value

* add k value to ask

* add k to similarity search
  • Loading branch information
asmorris committed Aug 21, 2023
1 parent 8a6d652 commit 0874cba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/langchain/vectorsearch/pinecone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def similarity_search_by_vector(embedding:, k: 4, namespace: "", filter: nil)
# @param filter [String] The filter to use
# @yield [String] Stream responses back one String at a time
# @return [String] The answer to the question
def ask(question:, namespace: "", filter: nil, &block)
search_results = similarity_search(query: question, namespace: namespace, filter: filter)
def ask(question:, namespace: "", filter: nil, k: 4, &block)
search_results = similarity_search(query: question, namespace: namespace, filter: filter, k: k)

context = search_results.map do |result|
result.dig("metadata").to_s
Expand Down
7 changes: 4 additions & 3 deletions spec/langchain/vectorsearch/pinecone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,12 @@
let(:question) { "How many times is \"lorem\" mentioned in this text?" }
let(:prompt) { "Context:\n#{metadata}\n---\nQuestion: #{question}\n---\nAnswer:" }
let(:answer) { "5 times" }
let(:k) { 4 }

describe "without a namespace" do
before do
allow(subject).to receive(:similarity_search).with(
query: question, namespace: "", filter: nil
query: question, namespace: "", filter: nil, k: k
).and_return(matches)
allow(subject.llm).to receive(:chat).with(prompt: prompt).and_return(answer)
end
Expand All @@ -322,7 +323,7 @@
describe "with a namespace" do
before do
allow(subject).to receive(:similarity_search).with(
query: question, namespace: namespace, filter: nil
query: question, namespace: namespace, filter: nil, k: k
).and_return(matches)
allow(subject.llm).to receive(:chat).with(prompt: prompt).and_return(answer)
end
Expand All @@ -335,7 +336,7 @@
describe "with a filter" do
before do
allow(subject).to receive(:similarity_search).with(
query: question, namespace: "", filter: filter
query: question, namespace: "", filter: filter, k: k
).and_return(matches)
allow(subject.llm).to receive(:chat).with(prompt: prompt).and_return(answer)
end
Expand Down

0 comments on commit 0874cba

Please sign in to comment.