-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add opt-in Pinecone retrieval practice #40
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
Changes from all commits
765bd9d
02b0a6d
cc14b44
d420d40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from typing import Any | ||
|
|
||
| from ai.embeddings.cohere_embedder import CohereEmbedder | ||
|
|
||
|
|
||
| class PineconeSearch: | ||
| """Pinecone alternative to the existing Qdrant semantic-search path.""" | ||
|
|
||
| def __init__(self, index_name: str | None = None): | ||
| api_key = os.getenv("PINECONE_API_KEY", "").strip() | ||
| self.index_name = ( | ||
| index_name or os.getenv("PINECONE_INDEX_NAME", "trojanchat") | ||
| ).strip() | ||
| self.namespace = os.getenv("PINECONE_NAMESPACE", "trojanchat").strip() | ||
|
|
||
| if not api_key: | ||
| raise RuntimeError( | ||
| "PINECONE_API_KEY is required when VECTOR_SEARCH_BACKEND=pinecone." | ||
| ) | ||
| if not self.index_name or not self.namespace: | ||
| raise RuntimeError("PINECONE_INDEX_NAME and PINECONE_NAMESPACE are required.") | ||
|
|
||
| from pinecone import Pinecone | ||
|
|
||
| self.index = Pinecone(api_key=api_key).Index(self.index_name) | ||
| self.embedder = CohereEmbedder() | ||
|
|
||
| def search( | ||
| self, | ||
| query: str, | ||
| top_k: int = 5, | ||
| filter_condition: dict[str, Any] | None = None, | ||
| ) -> list[dict[str, Any]]: | ||
| vector = self.embedder.embed_text(query) | ||
| response = self.index.query( | ||
| vector=vector, | ||
| top_k=top_k, | ||
| include_metadata=True, | ||
| namespace=self.namespace, | ||
| filter=filter_condition, | ||
| ) | ||
| return [ | ||
| { | ||
| "id": match.id, | ||
| "score": match.score, | ||
| "payload": match.metadata or {}, | ||
| } | ||
| for match in response.matches | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Optional hosted semantic-search backend. | ||
| pinecone>=6.0.0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In a clean environment following the documented install command, importing Useful? React with 👍 / 👎. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting
VECTOR_SEARCH_BACKEND=pineconehas no runtime effect because the setting is never read anywhere;ai/graph/langgraph_flow.pystill imports and unconditionally constructsQdrantSearchat lines 2 and 12. Consequently, every user following the new opt-in instructions continues querying Qdrant instead of the configured Pinecone index, so the advertised backend cannot be activated.Useful? React with 👍 / 👎.