LangChain integration for Oracle Coherence as a vector store.
Project description
LangChain Coherence Integration
This package integrates Oracle Coherence as a vector store in LangChain.
Installation
pip install langchain_coherence
Usage
Before using LangChain's CoherenceVectorStore you must ensure that a Coherence server (Coherence CE 25.03+ or Oracle Coherence 14.1.2+) is running
For local development, we recommend using the Coherence CE container image:
docker run -d -p 1408:1408 ghcr.io/oracle/coherence-ce:25.03.2
Adding and retrieving Documents
import asyncio
from langchain_coherence import CoherenceVectorStore
from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_huggingface.embeddings import HuggingFaceEmbeddings
from coherence import NamedMap, Session
async def do_run():
session: Session = await Session.create()
try:
named_map: NamedMap[str, Document] = await session.get_map("my-map")
embedding :Embeddings = HuggingFaceEmbeddings(
model_name="sentence-transformers/all-MiniLM-l6-v2")
# this embedding generates vectors of dimension 384
cvs :CoherenceVectorStore = await CoherenceVectorStore.create(
named_map,embedding,384)
d1 :Document = Document(id="1", page_content="apple")
d2 :Document = Document(id="2", page_content="orange")
documents = [d1, d2]
await cvs.aadd_documents(documents)
ids = [doc.id for doc in documents]
l = await cvs.aget_by_ids(ids)
assert len(l) == len(ids)
print("====")
for e in l:
print(e)
finally:
await session.close()
asyncio.run(do_run())
SimilaritySearch on Documents
from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_huggingface.embeddings import HuggingFaceEmbeddings
from coherence import NamedMap, Session
from langchain_core.vectorstores.coherence_store import CoherenceVectorStore
def test_data():
d1 :Document = Document(id="1", page_content="apple")
d2 :Document = Document(id="2", page_content="orange")
d3 :Document = Document(id="3", page_content="tiger")
d4 :Document = Document(id="4", page_content="cat")
d5 :Document = Document(id="5", page_content="dog")
d6 :Document = Document(id="6", page_content="fox")
d7 :Document = Document(id="7", page_content="pear")
d8 :Document = Document(id="8", page_content="banana")
d9 :Document = Document(id="9", page_content="plum")
d10 :Document = Document(id="10", page_content="lion")
documents = [d1, d2, d3, d4, d5, d6, d7, d8, d9, d10]
return documents
async def test_asimilarity_search():
documents = test_data()
session: Session = await Session.create()
try:
named_map: NamedMap[str, Document] = await session.get_map("my-map")
embedding :Embeddings = HuggingFaceEmbeddings(
model_name="sentence-transformers/all-MiniLM-l6-v2")
# this embedding generates vectors of dimension 384
cvs :CoherenceVectorStore = await CoherenceVectorStore.create(
named_map,embedding,384)
await cvs.aadd_documents(documents)
ids = [doc.id for doc in documents]
l = await cvs.aget_by_ids(ids)
assert len(l) == 10
result = await cvs.asimilarity_search("fruit")
assert len(result) == 4
print("====")
for e in result:
print(e)
finally:
await session.close()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_coherence-0.0.1.tar.gz.
File metadata
- Download URL: langchain_coherence-0.0.1.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4cbf717659c4e736ae0009f99555c8f2b5faaba838a7d79d2c61cf97c6554fd8
|
|
| MD5 |
9e80bb2ca44d6aee2cd03b6041138310
|
|
| BLAKE2b-256 |
0222714442717dfcc824f61c17549209288d530ea087e3eb2b653b218c080ba3
|
File details
Details for the file langchain_coherence-0.0.1-py3-none-any.whl.
File metadata
- Download URL: langchain_coherence-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78e81a062b9976d69dd4ac733855c792054d38788508b8d2b970c5216b22844f
|
|
| MD5 |
f8b1190843f4796f9e55d9d40b02f42f
|
|
| BLAKE2b-256 |
edf59b1614515cecf4571f6154d345290705341f303601400eaf17884b71e884
|