Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pinecone Native Integration #485

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

monami44
Copy link

@monami44 monami44 commented Nov 3, 2024

Pinecone Integration with Comprehensive Testing Suite

Overview

This PR introduces a comprehensive Pinecone integration along with extensive testing coverage across vector operations, RAG implementations, inference capabilities, and assistant functionalities.

Key Features

PineconeProvider Class

  • Implements a robust provider class that wraps Pinecone's functionality with instrumentation.
  • Handles both data plane and control plane operations.
  • Includes comprehensive error handling and event tracking.
  • Supports both traditional Pinecone operations and newer features like the Assistant API.
  • Note: Currently, there is no support for evaluating answers using the Assistant API.

Testing Suites

RAG Pipeline Test (pinecone_rag_test.py)

  • Tests the complete RAG (Retrieval-Augmented Generation) workflow.
  • Covers index creation, document embedding, and semantic search.
  • Implements vector operations (upsert, update, delete).
  • Tests collection management.
  • Includes real-world query testing with context retrieval.

Inference API Test (pinecone_inference_test.py)

  • Tests Pinecone's embedding generation capabilities.
  • Implements document reranking functionality.
  • Validates usage tracking and response formatting.
  • Tests various embedding models and configurations.

Assistant API Test (pinecone_assistant_test.py)

  • Tests Pinecone's Assistant API functionality.
  • Covers assistant creation, updating, and deletion.
  • Implements file upload and management.
  • Tests chat completions using an OpenAI-compatible interface.
  • Note: There is currently no support for evaluating answers within the Assistant API (premium tier feature)

Implementation Details

  • Comprehensive error handling and logging are included.
  • Event tracking for all operations is implemented.
  • Support for both synchronous and streaming responses is provided.
  • Proper cleanup of resources after each test is ensured.
  • Integrated with AgentOps for monitoring and tracking.

Testing Instructions

  1. Ensure that the required environment variables are set:

    • PINECONE_API_KEY
    • OPENAI_API_KEY (for RAG testing)
  2. Run individual test suites with the following commands:

    python tests/core_manual_tests/providers/pinecone_rag_test.py
    python tests/core_manual_tests/providers/pinecone_inference_test.py
    python tests/core_manual_tests/providers/pinecone_assistant_test.py

Notes

  • All tests are designed to be idempotent, ensuring no repeated impact on test results.
  • Comprehensive resource cleanup is included in all test flows.
  • Tests include rate limiting and appropriate delays to ensure API stability.
  • Extensive error handling and detailed reporting are part of the suite.

Future Improvements

  • Add support for batch operations to enhance efficiency.
  • Implement retry logic for handling transient failures.
  • Integrate custom embedding model support.
  • Enhance streaming response handling for smoother real-time interactions.

For more information, refer to the Pinecone Documentation.

Copy link

gitguardian bot commented Nov 3, 2024

⚠️ GitGuardian has uncovered 4 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
- - Generic High Entropy Secret 4570e65 agentops/llms/pinecone_test.py View secret
- - Generic High Entropy Secret 5b0a5b1 agentops/llms/pinecone_test.py View secret
- - Generic High Entropy Secret 5b0a5b1 agentops/llms/pinecone_test.py View secret
- - Generic High Entropy Secret 4570e65 agentops/llms/pinecone_test.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@areibman
Copy link
Contributor

areibman commented Nov 4, 2024

Amazing-- this is actually the first vectorDB integration PR we've seen so far. Will take a look soon @monami44.

In the meantime-- can you resolve the merge conflict?

@monami44
Copy link
Author

monami44 commented Nov 4, 2024

Hey @areibman , I just resolved the merge conflict. Also here is a video-walkthrough I sent to Adam as I submitted the PR. Hit me up if you want anything else to be changed

@areibman
Copy link
Contributor

areibman commented Nov 5, 2024

Super cool! @the-praxs and I can take a look

provider.delete_assistant(pc, "test-assistant")
print("Assistant deleted")

os.remove("test_data.txt")
Copy link
Contributor

@teocns teocns Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR tests should not write to physical file, but simulate doing so by writing memory.

Dangerous practice... in the rare but not impossible event this can lead to race conditions and surely host directory pollution, for which I suggest either standard pyfakefs or mktemp / tempfile to avoid file collision at the very least.

Both provisioning and teardown belong to a fixture or a provisioner (if I remember correctly pyfakefs already handles it for you).


Added pyfakefs in PR #490

@the-praxs
Copy link
Member

@monami44 I would request to do the following modifications -

  • Ensure that the chat_completions are stored as LLMEvent instead of ActionEvent. On the dashboard we use the LLM Chat tab to show the conversation between the user and the agents. Hence the chat_completions object's contents can be used for such tracking ability.
  • Create examples notebooks under examples directory so that one can understand how to use Pinecone and AgentOps together.

@the-praxs the-praxs linked an issue Nov 10, 2024 that may be closed by this pull request
3 tasks
@monami44
Copy link
Author

Hey @areibman @the-praxs @teocns !

I've updated to match the new version, created example notebooks, applied LLMEvent to pinecone assistant chat function as well as did tests with temporary files as asked. Please tell me if anything else needs changes.

Cheers,
Maksym

@the-praxs
Copy link
Member

Hey @areibman @the-praxs @teocns !

I've updated to match the new version, created example notebooks, applied LLMEvent to pinecone assistant chat function as well as did tests with temporary files as asked. Please tell me if anything else needs changes.

Cheers,

Maksym

I will look in a while. Thanks a lot!

@the-praxs
Copy link
Member

Linting is failing so please resolve that.

Copy link
Member

@the-praxs the-praxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most modifications are required in the Exception block where a pprint can help the user understand what's causing it.

Other changes are essential for code consistency and efficiency.

Also - please do the linting and resolve the errors with CI tests.

@dataclass
class VectorEvent(Event):
"""Event class for vector operations"""
event_type: str = "action"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect type annotation and value. This should be EventType with the value as EventType.VECTOR.value.

Since that events is missing in the EventType class, adding a VECTOR enum will resolve the issu.

self._safe_record(session, event)
return response
except Exception as e:
error_event = ErrorEvent(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to use pprint and print the Exception in the console for the user to see what's causing it.

"query": kwargs.get("query")
})
except Exception as e:
details["error"] = str(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other Exception block, pprint will look good!

self._safe_record(session, event)
return response
except Exception as e:
error_event = ErrorEvent(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other Exception block - pprint

result = orig(*args, **kwargs)
return self.handle_response(result, event_kwargs, init_timestamp, session=session)
except Exception as e:
# Create ActionEvent for the error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know what I mean :)

response = pc_instance.assistant.create_assistant(**kwargs)
return self._handle_assistant_response(response, "create_assistant", kwargs, init_timestamp, session)
except Exception as e:
error_event = ErrorEvent(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

response = assistant.chat_completions(messages=message_objects, stream=stream, model=model)

# Debug logging
print(f"Debug - Raw response: {response}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with logger.debug to ensure consistent logging.

return completion_text

except Exception as e:
print(f"Debug - Exception in chat_completions: {str(e)}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with logger.debug to ensure consistent logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Database Integration: Pinecone.
4 participants