Skip to content

Commit f2f0e0e

Browse files
nithishrErick Friis
and
Erick Friis
authored
couchbase: Add the initial version of Couchbase partner package (#22087)
Co-authored-by: Nithish Raghunandanan <[email protected]> Co-authored-by: Erick Friis <[email protected]>
1 parent 6c07eb0 commit f2f0e0e

File tree

23 files changed

+2122
-5
lines changed

23 files changed

+2122
-5
lines changed

docs/docs/integrations/vectorstores/couchbase.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
},
2424
{
2525
"cell_type": "code",
26-
"execution_count": null,
26+
"execution_count": 1,
2727
"id": "bec8d532-fec7-4dc7-9be3-020aa7bdb01f",
2828
"metadata": {},
2929
"outputs": [],
3030
"source": [
31-
"%pip install --upgrade --quiet langchain langchain-openai langchain-community couchbase"
31+
"%pip install --upgrade --quiet langchain langchain-openai langchain-couchbase"
3232
]
3333
},
3434
{
3535
"cell_type": "code",
36-
"execution_count": null,
36+
"execution_count": 2,
3737
"id": "4a972cbc-bf59-46eb-9b50-e5dc3a69dcf0",
3838
"metadata": {},
3939
"outputs": [],
@@ -59,7 +59,7 @@
5959
"metadata": {},
6060
"outputs": [],
6161
"source": [
62-
"from langchain_community.vectorstores import CouchbaseVectorStore\n",
62+
"from langchain_couchbase.vectorstores import CouchbaseVectorStore\n",
6363
"from langchain_openai import OpenAIEmbeddings"
6464
]
6565
},

libs/cli/langchain_cli/integration_template/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ integration_test integration_tests: TEST_FILE = tests/integration_tests/
1010

1111
# unit tests are run with the --disable-socket flag to prevent network calls
1212
test tests:
13-
poetry run pytest --disable-socket --allow-unit-socket $(TEST_FILE)
13+
poetry run pytest --disable-socket --allow-unix-socket $(TEST_FILE)
1414

1515
# integration tests are run without the --disable-socket flag to allow network calls
1616
integration_test integration_tests:

libs/community/langchain_community/vectorstores/couchbase.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import uuid
44
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, Type
55

6+
from langchain_core._api.deprecation import deprecated
67
from langchain_core.documents import Document
78
from langchain_core.embeddings import Embeddings
89
from langchain_core.vectorstores import VectorStore
@@ -11,6 +12,11 @@
1112
from couchbase.cluster import Cluster
1213

1314

15+
@deprecated(
16+
since="0.2.4",
17+
removal="0.3.0",
18+
alternative_import="langchain_couchbase.CouchbaseVectorStore",
19+
)
1420
class CouchbaseVectorStore(VectorStore):
1521
"""`Couchbase Vector Store` vector store.
1622

libs/partners/couchbase/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__pycache__
2+
# mypy
3+
.mypy_cache/

libs/partners/couchbase/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 LangChain, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libs/partners/couchbase/Makefile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
.PHONY: all format lint test tests integration_tests docker_tests help extended_tests
2+
3+
# Default target executed when no arguments are given to make.
4+
all: help
5+
6+
# Define a variable for the test file path.
7+
TEST_FILE ?= tests/unit_tests/
8+
integration_test integration_tests: TEST_FILE = tests/integration_tests/
9+
10+
11+
# unit tests are run with the --disable-socket flag to prevent network calls
12+
test tests:
13+
poetry run pytest --disable-socket --allow-unix-socket $(TEST_FILE)
14+
15+
# integration tests are run without the --disable-socket flag to allow network calls
16+
integration_test integration_tests:
17+
poetry run pytest $(TEST_FILE)
18+
19+
######################
20+
# LINTING AND FORMATTING
21+
######################
22+
23+
# Define a variable for Python and notebook files.
24+
PYTHON_FILES=.
25+
MYPY_CACHE=.mypy_cache
26+
lint format: PYTHON_FILES=.
27+
lint_diff format_diff: PYTHON_FILES=$(shell git diff --relative=libs/partners/couchbase --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$')
28+
lint_package: PYTHON_FILES=langchain_couchbase
29+
lint_tests: PYTHON_FILES=tests
30+
lint_tests: MYPY_CACHE=.mypy_cache_test
31+
32+
lint lint_diff lint_package lint_tests:
33+
poetry run ruff .
34+
poetry run ruff format $(PYTHON_FILES) --diff
35+
poetry run ruff --select I $(PYTHON_FILES)
36+
mkdir -p $(MYPY_CACHE); poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
37+
38+
format format_diff:
39+
poetry run ruff format $(PYTHON_FILES)
40+
poetry run ruff --select I --fix $(PYTHON_FILES)
41+
42+
spell_check:
43+
poetry run codespell --toml pyproject.toml
44+
45+
spell_fix:
46+
poetry run codespell --toml pyproject.toml -w
47+
48+
check_imports: $(shell find langchain_couchbase -name '*.py')
49+
poetry run python ./scripts/check_imports.py $^
50+
51+
######################
52+
# HELP
53+
######################
54+
55+
help:
56+
@echo '----'
57+
@echo 'check_imports - check imports'
58+
@echo 'format - run code formatters'
59+
@echo 'lint - run linters'
60+
@echo 'test - run unit tests'
61+
@echo 'tests - run unit tests'
62+
@echo 'test TEST_FILE=<test_file> - run all tests in file'

libs/partners/couchbase/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# langchain-couchbase
2+
3+
This package contains the LangChain integration with Couchbase
4+
5+
## Installation
6+
7+
```bash
8+
pip install -U langchain-couchbase
9+
```
10+
11+
## Usage
12+
13+
The `CouchbaseVectorStore` class exposes the connection to the Couchbase vector store.
14+
15+
```python
16+
from langchain_couchbase.vectorstores import CouchbaseVectorStore
17+
18+
from couchbase.cluster import Cluster
19+
from couchbase.auth import PasswordAuthenticator
20+
from couchbase.options import ClusterOptions
21+
from datetime import timedelta
22+
23+
auth = PasswordAuthenticator(username, password)
24+
options = ClusterOptions(auth)
25+
connect_string = "couchbases://localhost"
26+
cluster = Cluster(connect_string, options)
27+
28+
# Wait until the cluster is ready for use.
29+
cluster.wait_until_ready(timedelta(seconds=5))
30+
31+
embeddings = OpenAIEmbeddings()
32+
33+
vectorstore = CouchbaseVectorStore(
34+
cluster=cluster,
35+
bucket_name="",
36+
scope_name="",
37+
collection_name="",
38+
embedding=embeddings,
39+
index_name="vector-search-index",
40+
)
41+
42+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from langchain_couchbase.vectorstores import CouchbaseVectorStore
2+
3+
__all__ = [
4+
"CouchbaseVectorStore",
5+
]

libs/partners/couchbase/langchain_couchbase/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)