# Weaviate v4 Client not working with LangChain WeaviateVectorStore & ExampleSelector?

**URL:** <https://forum.weaviate.io/t/weaviate-v4-client-not-working-with-langchain-weaviatevectorstore-exampleselector/11869>\
**Category:** Support\
**Created:** [March 7, 2025, 8:38am UTC](https://forum.weaviate.io/t/weaviate-v4-client-not-working-with-langchain-weaviatevectorstore-exampleselector/11869 "2025-03-07T08:38:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jixy](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@Jixy](https://forum.weaviate.io/u/Jixy)\
**Post date:** [March 7, 2025, 8:38am UTC](https://forum.weaviate.io/t/weaviate-v4-client-not-working-with-langchain-weaviatevectorstore-exampleselector/11869/1 "2025-03-07T08:38:46Z")

</div>

### Problem:

I recently upgraded to **Weaviate v4** and tried to integrate it with LangChain’s `WeaviateVectorStore`. However, I encountered an error stating that my client must be an instance of `WeaviateClient`. Additionally, I am using `SemanticSimilarityExampleSelector` for few-shot learning, which now fails due to this issue.

* * *

### **My Code (With Hidden Configurations):**

```python
import weaviate
from weaviate.auth import AuthApiKey
from langchain.prompts import FewShotPromptTemplate, PromptTemplate
from langchain.prompts.example_selector import SemanticSimilarityExampleSelector
from langchain_weaviate.vectorstores import WeaviateVectorStore
from langchain_community.vectorstores import Weaviate
from src.embedding import AliyunEmbedding

# **Connect to Weaviate v4 Client**
client = weaviate.connect_to_custom(
    http_host="my-server-ip",
    http_port=8080,
    http_secure=False,
    grpc_host="my-server-ip",
    grpc_port=50051,
    grpc_secure=False,
    auth_credentials=AuthApiKey("my-api-key")
)

# **Initialize Embedding Model**
embedding_model = AliyunEmbedding(dimensions=1024)

# **Initialize Weaviate VectorStore**
vectorstore = WeaviateVectorStore(
    client=client,
    index_name="CypherExamples", # ✅ Stores Cypher query examples
    text_key="text",
    attributes=[],
    embedding=embedding_model
)

# **Instantiate ExampleSelector**
example_selector = SemanticSimilarityExampleSelector.from_examples(
    examples=[], # ✅ Weaviate handles retrieval, so no examples are needed
    vectorstore=vectorstore,
    embeddings=embedding_model, # ✅ Provide embeddings explicitly
    vectorstore_cls=WeaviateVectorStore, # ✅ Ensure correct vectorstore class
    k=3 # ✅ Retrieve top 3 most relevant examples
)

---

###Error Message:
ValueError: client must be an instance of WeaviateClient

---

Any guidance would be greatly appreciated!
```

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [March 10, 2025, 3:06pm UTC](https://forum.weaviate.io/t/weaviate-v4-client-not-working-with-langchain-weaviatevectorstore-exampleselector/11869/2 "2025-03-10T15:06:46Z")

</div>

hi @Jixy !!

You need to pass the `client`, `index_name` and `VectorStore` class, so `SemanticSimilarityExampleSelector` instantiate it for you.

I took the opportunity and wrote a recipe on this:

> **[recipes/integrations/llm-agent-frameworks/langchain/example-selector-similarity...](https://github.com/weaviate/recipes/tree/main/integrations/llm-agent-frameworks/langchain/example-selector-similarity)**
>
> This repository shares end-to-end notebooks on how to use various Weaviate features and integrations! - weaviate/recipes

```python
example_selector = SemanticSimilarityExampleSelector.from_examples(
    # The list of examples available to select from.
    examples,
    # The embedding class used to produce embeddings which are used to measure semantic similarity.
    OpenAIEmbeddings(),
    # The VectorStore class that is used to store the embeddings and do a similarity search over.
    WeaviateVectorStore,
    client=client,
    index_name="MyExamples",
    # The number of examples to produce.
    k=1,
)
similar_prompt = FewShotPromptTemplate(
    # We provide an ExampleSelector instead of examples.
    example_selector=example_selector,
    example_prompt=example_prompt,
    prefix="Give the antonym of every input",
    suffix="Input: {adjective}\nOutput:",
    input_variables=["adjective"],
)

```

This was crafted based doc in [How to select examples by similarity | 🦜️🔗 LangChain](https://python.langchain.com/docs/how_to/example_selectors_similarity/)

Let me know if that helps!

Thanks!

---

<div class="post-metadata">

**Author:** ![Jixy](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@Jixy](https://forum.weaviate.io/u/Jixy)\
**Post date:** [March 10, 2025, 3:23pm UTC](https://forum.weaviate.io/t/weaviate-v4-client-not-working-with-langchain-weaviatevectorstore-exampleselector/11869/3 "2025-03-10T15:23:54Z")

</div>

thank you very much，it works and the problems have been solved
