stanfordnlp / dspy

DSPy: The framework for programming—not prompting—foundation models
https://dspy-docs.vercel.app/
MIT License
16.67k stars 1.29k forks source link

ImportError: cannot import name 'FaissRM' from 'dspy.retrieve' #806

Closed levnikolaevich closed 5 months ago

levnikolaevich commented 5 months ago

Hello!

I'm trying to replicate an example from the documentation in Google Colab. https://dspy-docs.vercel.app/api/retrieval_model_clients/FaissRM

I'm encountering a problem.

================= import sys import os

import google.colab repo_path = 'dspy' !git -C $repo_path pull origin || git clone https://github.com/stanfordnlp/dspy $repo_path

if repo_path not in sys.path: sys.path.append(repo_path)

os.environ["DSP_NOTEBOOK_CACHEDIR"] = os.path.join(repo_path, 'cache')

import pkg_resources # Install the package if it's not installed if not "dspy-ai" in {pkg.key for pkg in pkg_resources.working_set}: !pip install -U pip

!pip install dspy-ai

!pip install -e $repo_path

!pip install transformers !pip install accelerate

================= import dspy from dspy.retrieve import FaissRM

document_chunks = [ "The superbowl this year was played between the San Francisco 49ers and the Kanasas City Chiefs", "Pop corn is often served in a bowl", ]

frm = FaissRM(document_chunks) turbo = dspy.OpenAI(model="gpt-3.5-turbo") dspy.settings.configure(lm=turbo, rm=frm) print(frm(["I am in the mood for Chinese food"]))


ImportError Traceback (most recent call last) in <cell line: 2>() 1 import dspy ----> 2 from dspy.retrieve import FaissRM 3 4 document_chunks = [ 5 "The superbowl this year was played between the San Francisco 49ers and the Kanasas City Chiefs",

ImportError: cannot import name 'FaissRM' from 'dspy.retrieve' (/content/dspy/dspy/retrieve/init.py)


Have the same problem locally too.

2024-04-11_20-36-10

Could you please advise what I might be doing wrong? Or is this an error?

Thank you very much in advance!

arnavsinghvi11 commented 5 months ago

ah thanks for raising this @levnikolaevich . the proper import line should be from dspy.retrieve.faiss_rm import FaissRM. Will update this in the documentation (but lmk if that doesn't work either!)

levnikolaevich commented 5 months ago

Thank you very much! Everything works! Will you close this topic yourself?

SardarArslan commented 1 month ago

How to save this vectorstore locally?