Comments (8)
Is there a way to pipe a FAISS index into this pipeline? Is there an example of how to ingest other vector DBs?
from dspy.
Yes! We’re almost done releasing that cc: @VThejas
from dspy.
See here: https://github.com/stanford-futuredata/ColBERT#running-a-lightweight-colbertv2-server
Before you launch the server, use the ColBERT intro notebook (or the Overview in the ColBERT README) to index your collection
from dspy.
A RAG example using Pinecone for retrieval would be helpful. Or... are there reasons not to use Pinecone here?
from dspy.
You can use Pinecone for sure, @drawal1. We don't have it built-in though. Would you like to add it?
We just need something as minimal as this wrapper for it:
import dspy
class Pinecone(dspy.Retrieve):
def __init__(self, k=3):
super().__init__(k=k)
# TODO: initialize pinecone here with any kwargs you need
def forward(self, query):
# TODO: passages = search with pinecone for self.k top passages for `query`
return dspy.Prediction(passages=passages)
For more info (probably not necessary), see https://github.com/stanfordnlp/dspy/blob/main/dspy/retrieve/retrieve.py
from dspy.
then you can use dspy.Pinecone instead of dspy.Retrieve (there's a cleaner way to do this, but we can start like that)
from dspy.
@okhat, ty! I tested below code and it works. I will submit a pull request if this looks reasonable
"""
Retriever model for Pinecone
"""
import pinecone # type: ignore
import openai # type: ignore
import dspy # type: ignore
OPENAI_API_KEY = 'YOUR OPENAPI KEY'
PINECONE_API_KEY = 'YOUR_PINECONE_API_KEY'
PINECONE_ENVIRONMENT = 'YOUR PINCONE ENVIRONMENT' # for example 'us-east4-gcp'
INDEX_NAME = "YOUR PINECONE INDEX NAME" # You should have an index build already. See Pinecone docs
EMBED_MODEL = "YOUR EMBEDDING MODEL" # For example 'text-embedding-ada-002' for OpenAI gpt-3.5-turbo
def init_pinecone(pinecone_api_key, pinecone_env, index_name):
"""Initialize pinecone and load the index"""
pinecone.init(
api_key=pinecone_api_key, # find at app.pinecone.io
environment=pinecone_env, # next to api key in console
)
return pinecone.Index(index_name)
PINECONE_INDEX = init_pinecone(PINECONE_API_KEY, PINECONE_ENVIRONMENT, INDEX_NAME)
class PineconeRM(dspy.Retrieve):
"""
Retrieve module for Pinecone
Example usage:
self.retrieve = PineconeRM(k=num_passages)
"""
def __init__(self, k=3):
super().__init__(k=k)
def forward(self, query_or_queries):
""" search with pinecone for self.k top passages for query"""
# convert query_or_queries to a python list if it is not
queries = [query_or_queries] if isinstance(query_or_queries, str) else query_or_queries
embedding = openai.Embedding.create(input=queries, engine=EMBED_MODEL, openai_api_key=OPENAI_API_KEY)
query_vec = embedding['data'][0]['embedding']
# retrieve relevant contexts from Pinecone (including the questions)
results_dict = PINECONE_INDEX.query(query_vec, top_k=self.k, include_metadata=True)
passages = [result['metadata']['text'] for result in results_dict['matches']]
return dspy.Prediction(passages=passages)
from dspy.
@okhat I have submitted the pull request, fyi
from dspy.
Related Issues (20)
- Add Community Contributions for Signatures, Prefixes, Postfixes and useful utilities in the release package HOT 2
- clarification on type of dspy.Prediction.context HOT 2
- unable to connect to the host: future-hgx-1 HOT 2
- Crash saving typed predictors with the '... is not JSON serializable' message HOT 2
- Bool output failing when using TypedPredictor HOT 1
- cannot pickle 'socket' object when using ReAct module with HFClientVLLM
- AttributeError: 'HFClientVLLM' object has no attribute 'model'
- LLM output appears cut-off (compared to the output of the same LLM and prompt in Langchain) HOT 4
- Would suggest COPRO ignore "return_outputs" HOT 1
- Implement Exponential Backoff for ThrottlingException in InvokeModel Calls HOT 2
- Error loading program compiled using the Ensemble optimizer HOT 2
- Support for Fireworks API Models with DSPY HOT 1
- Connection error. HOT 4
- Support for vLLM chat completion endpoint HOT 1
- There is a small error in the example in signature-optimizer.mdx.
- Inspect_history only shows the last history regardless of n/skip HOT 2
- Circular import and NameError in Cohere Module HOT 4
- Update weaviate_rm.py with v4 WeaviateClient
- Enhance error handling HOT 4
- DPSy Assistant HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dspy.