fix pinecone (#2414)

This commit is contained in:
Dev Khant
2025-03-20 23:47:09 +05:30
committed by GitHub
parent 8e6a08aa83
commit 3cc7013fde
2 changed files with 21 additions and 14 deletions

View File

@@ -2,6 +2,8 @@
[Pinecone](https://www.pinecone.io/) is a fully managed vector database designed for machine learning applications, offering high performance vector search with low latency at scale. It's particularly well-suited for semantic search, recommendation systems, and other AI-powered applications. [Pinecone](https://www.pinecone.io/) is a fully managed vector database designed for machine learning applications, offering high performance vector search with low latency at scale. It's particularly well-suited for semantic search, recommendation systems, and other AI-powered applications.
> **Note**: Before configuring Pinecone, you need to select an embedding model (e.g., OpenAI, Cohere, or custom models) and ensure the `embedding_model_dims` in your config matches your chosen model's dimensions. For example, OpenAI's text-embedding-ada-002 uses 1536 dimensions.
### Usage ### Usage
```python ```python
@@ -11,13 +13,17 @@ from mem0 import Memory
os.environ["OPENAI_API_KEY"] = "sk-xx" os.environ["OPENAI_API_KEY"] = "sk-xx"
os.environ["PINECONE_API_KEY"] = "your-api-key" os.environ["PINECONE_API_KEY"] = "your-api-key"
# Example using serverless configuration
config = { config = {
"vector_store": { "vector_store": {
"provider": "pinecone", "provider": "pinecone",
"config": { "config": {
"collection_name": "memory_index", "collection_name": "testing",
"embedding_model_dims": 1536, "embedding_model_dims": 1536, # Matches OpenAI's text-embedding-3-small
"environment": "us-west1-gcp", "serverless_config": {
"cloud": "aws", # Choose between 'aws' or 'gcp' or 'azure'
"region": "us-east-1"
},
"metric": "cosine" "metric": "cosine"
} }
} }
@@ -40,28 +46,29 @@ Here are the parameters available for configuring Pinecone:
| Parameter | Description | Default Value | | Parameter | Description | Default Value |
| --- | --- | --- | | --- | --- | --- |
| `collection_name` | Name of the index/collection | Required | | `collection_name` | Name of the index/collection | Required |
| `embedding_model_dims` | Dimensions of the embedding model | Required | | `embedding_model_dims` | Dimensions of the embedding model (must match your chosen embedding model) | Required |
| `client` | Existing Pinecone client instance | `None` | | `client` | Existing Pinecone client instance | `None` |
| `api_key` | API key for Pinecone | Environment variable: `PINECONE_API_KEY` | | `api_key` | API key for Pinecone | Environment variable: `PINECONE_API_KEY` |
| `environment` | Pinecone environment | `None` | | `environment` | Pinecone environment | `None` |
| `serverless_config` | Configuration for serverless deployment | `None` | | `serverless_config` | Configuration for serverless deployment (AWS or GCP or Azure) | `None` |
| `pod_config` | Configuration for pod-based deployment | `None` | | `pod_config` | Configuration for pod-based deployment | `None` |
| `hybrid_search` | Whether to enable hybrid search | `False` | | `hybrid_search` | Whether to enable hybrid search | `False` |
| `metric` | Distance metric for vector similarity | `"cosine"` | | `metric` | Distance metric for vector similarity | `"cosine"` |
| `batch_size` | Batch size for operations | `100` | | `batch_size` | Batch size for operations | `100` |
#### Serverless Config Example > **Important**: You must choose either `serverless_config` or `pod_config` for your deployment, but not both.
#### Serverless Config Example
```python ```python
config = { config = {
"vector_store": { "vector_store": {
"provider": "pinecone", "provider": "pinecone",
"config": { "config": {
"collection_name": "memory_index", "collection_name": "memory_index",
"embedding_model_dims": 1536, "embedding_model_dims": 1536, # For OpenAI's text-embedding-3-small
"serverless_config": { "serverless_config": {
"cloud": "aws", "cloud": "aws", # or "gcp" or "azure"
"region": "us-west-2" "region": "us-east-1" # Choose appropriate region
} }
} }
} }
@@ -69,14 +76,13 @@ config = {
``` ```
#### Pod Config Example #### Pod Config Example
```python ```python
config = { config = {
"vector_store": { "vector_store": {
"provider": "pinecone", "provider": "pinecone",
"config": { "config": {
"collection_name": "memory_index", "collection_name": "memory_index",
"embedding_model_dims": 1536, "embedding_model_dims": 1536, # For OpenAI's text-embedding-ada-002
"pod_config": { "pod_config": {
"environment": "gcp-starter", "environment": "gcp-starter",
"replicas": 1, "replicas": 1,

View File

@@ -199,12 +199,13 @@ class PineconeDB(VectorStoreBase):
return pinecone_filter return pinecone_filter
def search(self, query: List[float], limit: int = 5, filters: Optional[Dict] = None) -> List[OutputData]: def search(self, query: str, vectors: List[float], limit: int = 5, filters: Optional[Dict] = None) -> List[OutputData]:
""" """
Search for similar vectors. Search for similar vectors.
Args: Args:
query (list): Query vector. query (str): Query.
vectors (list): List of vectors to search.
limit (int, optional): Number of results to return. Defaults to 5. limit (int, optional): Number of results to return. Defaults to 5.
filters (dict, optional): Filters to apply to the search. Defaults to None. filters (dict, optional): Filters to apply to the search. Defaults to None.
@@ -214,7 +215,7 @@ class PineconeDB(VectorStoreBase):
filter_dict = self._create_filter(filters) if filters else None filter_dict = self._create_filter(filters) if filters else None
query_params = { query_params = {
"vector": query, "vector": vectors,
"top_k": limit, "top_k": limit,
"include_metadata": True, "include_metadata": True,
"include_values": False, "include_values": False,