langchainrb: Vector search with Qdrant doesn't create vectors

I never used Qdrant, but when using this simple example:

openai = Langchain::LLM::OpenAI.new(api_key: ENV['OPENAI_API_KEY'])

qdrant = Langchain::Vectorsearch::Qdrant.new(
  url: ENV["QDRANT_URL"],
  api_key: nil,
  index_name: ENV["QDRANT_INDEX"],
  llm: openai
)

qdrant.create_default_schema

qdrant.add_texts(
  texts: [
      "Begin by preheating your oven to 375°F (190°C). Prepare four boneless, skinless chicken breasts by cutting a pocket into the side of each breast, being careful not to cut all the way through. Season the chicken with salt and pepper to taste. In a large skillet, melt 2 tablespoons of unsalted butter over medium heat. Add 1 small diced onion and 2 minced garlic cloves, and cook until softened, about 3-4 minutes. Add 8 ounces of fresh spinach and cook until wilted, about 3 minutes. Remove the skillet from heat and let the mixture cool slightly.",
      "In a bowl, combine the spinach mixture with 4 ounces of softened cream cheese, 1/4 cup of grated Parmesan cheese, 1/4 cup of shredded mozzarella cheese, and 1/4 teaspoon of red pepper flakes. Mix until well combined. Stuff each chicken breast pocket with an equal amount of the spinach mixture. Seal the pocket with a toothpick if necessary. In the same skillet, heat 1 tablespoon of olive oil over medium-high heat. Add the stuffed chicken breasts and sear on each side for 3-4 minutes, or until golden brown."
  ]
)

qdrant.similarity_search(
  query: 'chicken',
  k: 5
)

I get the following result back:

{"result"=>
  [{"id"=>"6c0a523b-adea-4061-88c5-82a62a315339",
    "version"=>0,
    "score"=>0.7885697,
    "payload"=>
     {"content"=>
       "Begin by preheating your oven to 375°F (190°C). Prepare four boneless, skinless chicken breasts by cutting a pocket into the side of each breast, being careful not to cut all the way through. Season the chicken with salt and pepper to taste. In a large skillet, melt 2 tablespoons of unsalted butter over medium heat. Add 1 small diced onion and 2 minced garlic cloves, and cook until softened, about 3-4 minutes. Add 8 ounces of fresh spinach and cook until wilted, about 3 minutes. Remove the skillet from heat and let the mixture cool slightly."},
    "vector"=>nil},
   {"id"=>"cb2d6bda-4cec-4226-94a3-11596af910f3",
    "version"=>0,
    "score"=>0.78527427,
    "payload"=>
     {"content"=>
       "In a bowl, combine the spinach mixture with 4 ounces of softened cream cheese, 1/4 cup of grated Parmesan cheese, 1/4 cup of shredded mozzarella cheese, and 1/4 teaspoon of red pepper flakes. Mix until well combined. Stuff each chicken breast pocket with an equal amount of the spinach mixture. Seal the pocket with a toothpick if necessary. In the same skillet, heat 1 tablespoon of olive oil over medium-high heat. Add the stuffed chicken breasts and sear on each side for 3-4 minutes, or until golden brown."},
    "vector"=>nil}],
 "status"=>"ok",
 "time"=>0.000397917}

Note that the vectors are nil for both results. The embeddings are apparently created, since it takes a bit to ingest the text samples, but the vectors are not put into Qdrant.

Another thing to improve: Using qdrant.create_default_schema throws an error when the collection was already created. Would make sense to check first if the collection exists and only then try to create it.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@andreibondarev Awesome, thanks!

@andreibondarev Sounds like an even better solution 👍

@andreibondarev Not sure if it fits the other databases, but I’ll have a look tomorrow and see if I can come up with something usable.

I just hardcoded it, it’s on the main branch. Could you please try it out?