vanna icon indicating copy to clipboard operation
vanna copied to clipboard

PGVector support

Open dcieslak19973 opened this issue 1 year ago • 8 comments

For larger / more diverse query histories would be nice to externalize the Vector Store to something like PostGres w/ the vector extension

dcieslak19973 avatar Sep 01 '23 01:09 dcieslak19973

would be interested in this as well- for REDIS

luzer avatar Oct 06 '23 14:10 luzer

Could install pg_trgm extension and, optionally pg_similarity.

v0nerd avatar Oct 12 '23 02:10 v0nerd

This would be of interest to us as well. Any thoughts, @zainhoda? I believe you may use pgvector for your production applications?

If the pgvector vector store implementation is already accessible, it would be nice to avoid implementing it from scratch to add support. But if not, I could give it a go and draft a PR.

andreped avatar Feb 29 '24 08:02 andreped

This will a great addition to Vanna. We currently use pgvector as well for embeddings as it keeps the tech stack leaner without adding another database variant for vectors. @zainhoda

navikohli avatar Mar 15 '24 14:03 navikohli

Shouldn’t this work out of the box, as the hosted version already uses PGVec. Just would need to ask the team on how we could enable a self-hosted PGVec instance instead of the cloud hosted instance.

@vanna Team - thanks for an excellent setup and a great starting point. Let’s take this somewhere even better…

tomthebuzz avatar Apr 23 '24 06:04 tomthebuzz

@tomthebuzz so generally when people want to use pgvector they want it because they already use postgres for their data. The tricky part comes in the setup (need to install pgvector, create the necessary tables, etc)

We do use pgvector for our hosted vector database and this is a snippet of what that looks like:

from sqlalchemy.orm import sessionmaker, mapped_column, declarative_base, relationship

Base = declarative_base()

class DDLEmbedding(Base):
    __tablename__ = 'ddl_embedding'
    id = Column(Integer, primary_key=True)
    created_at = Column(DateTime, default=func.current_timestamp(), server_default=text('CURRENT_TIMESTAMP'))
    updated_at = Column(DateTime, default=func.current_timestamp(), server_default=text('CURRENT_TIMESTAMP'), onupdate=func.current_timestamp())
    ddl_id = Column(Integer, ForeignKey('ddl.id'), nullable=False)
    embedding = mapped_column(Vector(1536))

    ddl = relationship("DDL")

class DocumentationEmbedding(Base):
    __tablename__ = 'documentation_embedding'
    id = Column(Integer, primary_key=True)
    created_at = Column(DateTime, default=func.current_timestamp(), server_default=text('CURRENT_TIMESTAMP'))
    updated_at = Column(DateTime, default=func.current_timestamp(), server_default=text('CURRENT_TIMESTAMP'), onupdate=func.current_timestamp())
    documentation_id = Column(Integer, ForeignKey('documentation.id'), nullable=False)
    embedding = mapped_column(Vector(1536))

    documentation = relationship("Documentation")

We can't port it over one-for-one from our hosted server because it's tightly integrated with the rest of our data model.

If someone would like to take this and run with it, we're happy to accept a PR for it

zainhoda avatar Apr 23 '24 13:04 zainhoda

so generally when people want to use pgvector they want it because they already use postgres for their data. The tricky part comes in the setup (need to install pgvector, create the necessary tables, etc)

Yeah, thats true, but I would think there is a lot of people who want to use pgvector just as a vector store, as it is highly performant and more suited for production than say Chroma. Their documentation state that the HttpClient is the prefer client for production use (see here), but most people testing Chroma says that it is not that mature yet - then again great for prototyping and for PoCs.

We will be testing pgvector quite soon, hopefully migrate our solution to it, and if we make an implementation that makes sense for others (plug-and-play), I could potentially make a PR. Will keep you updated.

Regardless, it would be nice to discuss some implementation details, if we hit a wall, @zainhoda :]

andreped avatar May 16 '24 09:05 andreped

How can I use this store to implement customized RAG approach? (not to use platform services)

v0nerd avatar May 16 '24 10:05 v0nerd