Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix couchbase vectordb support #987

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
629e878
add Couchbase VectorDB Support for AG2
lokesh-couchbase Dec 9, 2024
6a9faf8
resolve formatting issues
lokesh-couchbase Dec 10, 2024
d5158eb
remove healthcheck
lokesh-couchbase Dec 10, 2024
ea37b99
improve information on cluster setup
lokesh-couchbase Jan 20, 2025
513bb66
Merge remote-tracking branch 'origin/main' into couchbase-vectordb-su…
marklysze Jan 23, 2025
31cb817
Remove old documentation
marklysze Feb 6, 2025
4952aa8
fix couchbase test
lokesh-couchbase Feb 10, 2025
10d215d
merge main
lokesh-couchbase Feb 12, 2025
bfb0978
update header
lokesh-couchbase Feb 12, 2025
5d9d489
resolve merge conflicts
lokesh-couchbase Feb 12, 2025
df237bc
resolve merge conflicts
lokesh-couchbase Feb 12, 2025
da666fd
resolve merge conflicts
lokesh-couchbase Feb 12, 2025
08be91e
add couchbase retrievechat package to installer
lokesh-couchbase Feb 12, 2025
37c149d
Merge branch 'main' into couchbase-vectordb-support
marklysze Feb 14, 2025
7a6517a
pre-commit fixes
marklysze Feb 14, 2025
3541738
Add to tests
marklysze Feb 14, 2025
148fb00
Update couchbase with import utils
marklysze Feb 14, 2025
bebb359
SentenceTransformers import issue
marklysze Feb 14, 2025
fc85911
Attempt to skip warning
marklysze Feb 14, 2025
c8ef866
Add sentence transformers to optional import
marklysze Feb 14, 2025
0204839
Merge branch 'main' into couchbase-vectordb-support
davorrunje Feb 14, 2025
48885ed
pre-commit fixed
davorrunje Feb 14, 2025
8d1ea19
typing fixed
davorrunje Feb 14, 2025
9b20798
fixes
davorrunje Feb 14, 2025
f5dff9f
fixes
davorrunje Feb 14, 2025
bf5705f
fixes
davorrunje Feb 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/contrib-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ jobs:
image: mongodb/mongodb-atlas-local:latest
ports:
- 27017:27017
couchbase:
image: couchbase:enterprise-7.6.3
ports:
- "8091-8095:8091-8095"
- "11210:11210"
- "9102:9102"
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
Expand All @@ -116,6 +122,9 @@ jobs:
- name: Install pgvector when on linux
run: |
uv pip install --system -e .[test,retrievechat-pgvector,retrievechat-mongodb]
- name: Install couchbase when on linux
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this pip install can be combined with the above pip install statement at line 124

run: |
uv pip install --system -e .[retrievechat-couchbase]
- name: Set AUTOGEN_USE_DOCKER based on OS
shell: bash
run: |
Expand All @@ -130,7 +139,7 @@ jobs:
uses: codecov/codecov-action@v5
with:
files: ./coverage.xml
flags: retrievechat, retrievechat-qdrant, retrievechat-pgvector, retrievechat-mongodb, ubuntu-latest, ${{ matrix.python-version }}
flags: retrievechat, retrievechat-qdrant, retrievechat-pgvector, retrievechat-mongodb, retrievechat-couchbase, ubuntu-latest, ${{ matrix.python-version }}
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-with-optional-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
- "commsagent-telegram"
- "jupyter-executor"
- "retrievechat"
- "retrievechat-couchbase"
- "retrievechat-pgvector"
- "retrievechat-mongodb"
- "retrievechat-qdrant"
Expand Down
2 changes: 1 addition & 1 deletion autogen/agentchat/contrib/llamaindex_conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ... import OpenAIWrapper
from ...import_utils import optional_import_block, require_optional_import
from .. import Agent, ConversableAgent
from .vectordb.utils import get_logger
from .vectordb import get_logger

logger = get_logger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ...import_utils import optional_import_block, require_optional_import
from ...retrieve_utils import TEXT_FORMATS, get_files_from_dir, split_files_to_chunks
from ..contrib.retrieve_user_proxy_agent import RetrieveUserProxyAgent
from ..contrib.vectordb.utils import (
from ..contrib.vectordb import (
chroma_results_to_query_results,
filter_results_by_distance,
get_logger,
Expand Down
7 changes: 5 additions & 2 deletions autogen/agentchat/contrib/retrieve_user_proxy_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
from ...token_count_utils import count_token
from .. import UserProxyAgent
from ..agent import Agent
from ..contrib.vectordb.base import Document, QueryResults, VectorDB, VectorDBFactory
from ..contrib.vectordb.utils import (
from ..contrib.vectordb import (
Document,
QueryResults,
VectorDB,
VectorDBFactory,
chroma_results_to_query_results,
filter_results_by_distance,
get_logger,
Expand Down
17 changes: 16 additions & 1 deletion autogen/agentchat/contrib/vectordb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@
#
# SPDX-License-Identifier: Apache-2.0

__all__: list[str] = []
from .base import Document, QueryResults, VectorDB, VectorDBFactory
from .utils import (
chroma_results_to_query_results,
filter_results_by_distance,
get_logger,
)

__all__ = [
"Document",
"QueryResults",
"VectorDB",
"VectorDBFactory",
"chroma_results_to_query_results",
"filter_results_by_distance",
"get_logger",
]
15 changes: 11 additions & 4 deletions autogen/agentchat/contrib/vectordb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
runtime_checkable,
)

from ....doc_utils import export_module

Metadata = Union[Mapping[str, Any], None]
Vector = Union[Sequence[float], Sequence[int]]
ItemID = Union[str, int] # chromadb doesn't support int ids, VikingDB does


@export_module("agentchat.contrib.vectordb")
class Document(TypedDict):
"""A Document is a record in the vector database.

Expand All @@ -42,6 +45,7 @@ class Document(TypedDict):
QueryResults = list[list[tuple[Document, float]]]


@export_module("agentchat.contrib.vectordb")
@runtime_checkable
class VectorDB(Protocol):
"""Abstract class for vector database. A vector database is responsible for storing and retrieving documents.
Expand All @@ -63,9 +67,7 @@ class VectorDB(Protocol):

active_collection: Any = None
type: str = ""
embedding_function: Optional[Callable[[list[str]], list[list[float]]]] = (
None # embeddings = embedding_function(sentences)
)
embedding_function: Optional[Callable[[list[str]], list[list[float]]]] = None

def create_collection(self, collection_name: str, overwrite: bool = False, get_or_create: bool = True) -> Any:
"""Create a collection in the vector database.
Expand Down Expand Up @@ -190,10 +192,11 @@ def get_docs_by_ids(
...


@export_module("agentchat.contrib.vectordb")
class VectorDBFactory:
"""Factory class for creating vector databases."""

PREDEFINED_VECTOR_DB = ["chroma", "pgvector", "mongodb", "qdrant"]
PREDEFINED_VECTOR_DB = ["chroma", "pgvector", "mongodb", "qdrant", "couchbase"]

@staticmethod
def create_vector_db(db_type: str, **kwargs) -> VectorDB:
Expand Down Expand Up @@ -222,6 +225,10 @@ def create_vector_db(db_type: str, **kwargs) -> VectorDB:
from .qdrant import QdrantVectorDB

return QdrantVectorDB(**kwargs)
if db_type.lower() in ["couchbase", "couchbasedb", "capella"]:
from .couchbase import CouchbaseVectorDB

return CouchbaseVectorDB(**kwargs)
else:
raise ValueError(
f"Unsupported vector database type: {db_type}. Valid types are {VectorDBFactory.PREDEFINED_VECTOR_DB}."
Expand Down
Loading
Loading