Skip to content

fix Update qdrant_impl.py #1253

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions lightrag/kg/qdrant_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,50 @@ async def search_by_prefix(self, prefix: str) -> list[dict[str, Any]]:
except Exception as e:
logger.error(f"Error searching for prefix '{prefix}': {e}")
return []

async def get_by_id(self, id: str) -> dict[str, Any] | None:
"""Get vector data by its ID

Args:
id: The unique identifier of the vector

Returns:
The vector data if found, or None if not found
"""
try:
qdrant_id = compute_mdhash_id_for_qdrant(id)
result = self._client.retrieve(
collection_name=self.namespace,
ids=[qdrant_id],
with_payload=True
)
if result and len(result) > 0:
return {**result[0].payload}
return None
except Exception as e:
logger.error(f"Error getting vector by ID {id}: {e}")
return None

async def get_by_ids(self, ids: list[str]) -> list[dict[str, Any]]:
"""Get multiple vector data by their IDs

Args:
ids: List of unique identifiers

Returns:
List of vector data objects that were found
"""
if not ids:
return []

try:
qdrant_ids = [compute_mdhash_id_for_qdrant(id) for id in ids]
results = self._client.retrieve(
collection_name=self.namespace,
ids=qdrant_ids,
with_payload=True
)
return [{**point.payload} for point in results if point]
except Exception as e:
logger.error(f"Error getting vectors by IDs: {e}")
return []
2 changes: 1 addition & 1 deletion lightrag/operate.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ async def get_kg_context():

async def get_vector_context():
# Consider conversation history in vector search
augmented_query = query
augmented_query = f"Instructions: Based on the user query, provide a list of relevant documents that are most likely to contain the answer to the user's query.\nQuery: {query}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

@LarFii Please review whether the changes here are reasonable.

Copy link
Author

Choose a reason for hiding this comment

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

oh I forgot to exclude that part . that doesn't relate to the main issue. i'm using an instruct version of the e5 model and that format is required for it to function properly. I hope there's a higher level config that allows user to easily do that without modifying the internal module.

if history_context:
augmented_query = f"{history_context}\n{query}"

Expand Down
Loading