langchain: Fix Neo4jVector vector store reference from partner package for self query (#28292)

_This should only be merged once neo4j is included under libs/partners._

# **Description:**

Neo4jVector from langchain-community is being moved to langchain-neo4j:
[see
link](https://github.com/langchain-ai/langchain-neo4j/blob/main/libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py#L436).

To solve the issue below, this PR adds an attempt to import
`Neo4jVector` from the partner package `langchain-neo4j`, similarly to
the other partner packages.

# **Issue:**
When initializing `SelfQueryRetriever`, the following error is raised:

```
ValueError: Self query retriever with Vector Store type <class 'langchain_neo4j.vectorstores.neo4j_vector.Neo4jVector'> not supported.
```

[See related
issue](https://github.com/langchain-ai/langchain/issues/19748).

# **Dependencies:**
- langchain-neo4j
This commit is contained in:
willtai 2024-11-26 18:21:04 +00:00 committed by GitHub
parent a1c90794e1
commit 7d95a10ada
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -161,6 +161,14 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor:
if isinstance(vectorstore, MongoDBAtlasVectorSearch): if isinstance(vectorstore, MongoDBAtlasVectorSearch):
return MongoDBAtlasTranslator() return MongoDBAtlasTranslator()
try:
from langchain_neo4j import Neo4jVector
except ImportError:
pass
else:
if isinstance(vectorstore, Neo4jVector):
return Neo4jTranslator()
try: try:
from langchain_chroma import Chroma from langchain_chroma import Chroma
except ImportError: except ImportError: